Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot upload file into OneDrive (content type error) #1276

Open
4 tasks done
jakubriegel opened this issue May 12, 2023 · 5 comments
Open
4 tasks done

Cannot upload file into OneDrive (content type error) #1276

jakubriegel opened this issue May 12, 2023 · 5 comments
Assignees

Comments

@jakubriegel
Copy link

Bug Report

Prerequisites

  • Can you reproduce the problem?
  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

Cannot make a PUT request to upload file into OneDrive. The API returns Unable to read JSON request payload error. The docs here say to use text/plain content type, but the library here has it hardcoded to JSON.

Console Errors: [Is there any console error]

{
  statusCode: 400,
  code: 'BadRequest',
  requestId: '6418fb30-de6e-4b41-a53c-7e96eebc348b',
  date: 2023-05-12T07:51:14.000Z,
  body: '{"code":"BadRequest","message":"Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.","innerError":{"date":"2023-05-12T09:51:14","request-id":"6418fb30-de6e-4b41-a53c-7e96eebc348b","client-request-id":"8142eabc-e22d-a7eb-c8f6-be9ebc37899f"}}',
  headers: Headers {
    [Symbol(map)]: [Object: null prototype] {
      'transfer-encoding': [ 'chunked' ],
      'content-type': [ 'application/json' ],
      'content-encoding': [ 'gzip' ],
      vary: [ 'Accept-Encoding' ],
      'strict-transport-security': [ 'max-age=31536000' ],
      'request-id': [ '6418fb30-de6e-4b41-a53c-7e96eebc348b' ],
      'client-request-id': [ '8142eabc-e22d-a7eb-c8f6-be9ebc37899f' ],
      'x-ms-ags-diagnostic': [
        '{"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"002","RoleInstance":"AM2PEPF0000BE20"}}'
      ],
      date: [ 'Fri, 12 May 2023 09:51:13 GMT' ],
      connection: [ 'close' ]
    }
  }
}

Screenshots: [If applicable, add screenshots to help explain your problem]

Steps to Reproduce

const filename = 'file.csv';
const content = 'content';
await.client.api(`/drives/${this.driveId}/items/${this.folderId}:/${filename}:/content`).put(content);

Expected behavior: PUT is succesfully sent and file is uploaded

Actual behavior: PUT was sent with invalid content type

Additional Context

Add any other context about the problem here..

Usage Information

check log above

@ghost ghost added the ToTriage label May 12, 2023
@jakubriegel
Copy link
Author

I've changed my code so that it sets content type explicitly:

const filename = 'file.csv';
const content = 'content';
await.client.api(`/drives/${this.driveId}/items/${this.folderId}:/${filename}:/content`)
    .headers({'Content-Type': 'text/plain'})
    .put(content);

The request now matches documentation, but I still get an error:

{
  statusCode: 400,
  code: 'BadRequest',
  requestId: '69596a36-0fdd-44f1-aa12-02d1b7373707',
  date: 2023-05-12T08:14:24.000Z,
  body: '{"code":"BadRequest","message":"Entity only allows writes with a JSON Content-Type header.","innerError":{"date":"2023-05-12T10:14:24","request-id":"69596a36-0fdd-44f1-aa12-02d1b7373707","client-request-id":"9d35cfcc-21f3-74ba-78cc-ea0accc4d93a"}}',
  headers: Headers {
    [Symbol(map)]: [Object: null prototype] {
      'transfer-encoding': [ 'chunked' ],
      'content-type': [ 'application/json' ],
      'content-encoding': [ 'gzip' ],
      vary: [ 'Accept-Encoding' ],
      'strict-transport-security': [ 'max-age=31536000' ],
      'request-id': [ '69596a36-0fdd-44f1-aa12-02d1b7373707' ],
      'client-request-id': [ '9d35cfcc-21f3-74ba-78cc-ea0accc4d93a' ],
      'x-ms-ags-diagnostic': [
        '{"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"AM4PEPF000251A9"}}'
      ],
      date: [ 'Fri, 12 May 2023 10:14:23 GMT' ],
      connection: [ 'close' ]
    }
  }
}

@sebastienlevert
Copy link
Contributor

@koros, can you have a look?

@vladtsit
Copy link

Hi @jakubriegel have you solved the problem?

@jakubriegel
Copy link
Author

@vladtsit No, as this issue needs to be resolved on library level. But I have a workaround.

I used https://learn.microsoft.com/pl-pl/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online. I create an upload url with the Client provided by Microsoft and then use received upload url to PUT the file with Axios.

cc: @sebastienlevert @koros

@tboulis
Copy link

tboulis commented Oct 24, 2023

Im facing the same issue, any progress so far?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants