0

400 Client Error: Bad Request for url:

https://XXXXX.sharepoint.com/sites/QE/_api/Web/getFolderByServerRelativeUrl('Shared Documents/product-health-metrics')/Files/add(overwrite=true,url='C:/Users/A5553/Downloads/XXXXX-salesiq-ce-iqs-open-20221130.csv

Receiving this error while trying to upload files to SharePoint. I am not able to resolve the issue.

Can somebody please tell me how to deal with this?

1 Answer 1

0

You cannot write using a local file, like, C:/Users/A5553/Downloads/XXXXX-salesiq-ce-iqs-open-20221130.csv, this just needs to be FILENAME.extension, and then followed by the content of the file in bytes array.

https://learn.microsoft.com/de-de/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest

From the official MS Documentation,

POST https://{site_url}/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/add(url='a.txt',overwrite=true)
Authorization: "Bearer " + accessToken
Content-Length: {length of request body as integer}
X-RequestDigest: "{form_digest_value}"

"Contents of file"


function getBuffer(resolve) {
    var reader = new FileReader();
    reader.readAsArrayBuffer(fileData);
    reader.onload = function() {
      var arrayBuffer = reader.result
      var bytes = new Uint8Array(arrayBuffer);
      resolve(bytes);
    }
  }
3
  • 1
    Hi, Thanks for reverting. But I am yet not clear with the fact of how to add the content of file?
    – Kompal
    Commented Dec 1, 2022 at 6:44
  • Hi, I could not follow up how to add the content of the files
    – Kompal
    Commented Dec 1, 2022 at 7:27
  • Hi, @Kompal, I added a function to read bytes from a file array Commented Dec 2, 2022 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.