Open jakubriegel opened 1 year ago
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' ]
}
}
}
@koros, can you have a look?
Hi @jakubriegel have you solved the problem?
@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
Im facing the same issue, any progress so far?
Bug Report
Prerequisites
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 usetext/plain
content type, but the library here has it hardcoded to JSON.Console Errors: [Is there any console error]
Screenshots: [If applicable, add screenshots to help explain your problem]
Steps to Reproduce
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