How to upload a file to OneDrive using the OneDrive REST API?

Please let me explain what , what I do, and How , I do.

What am I doing?

I am trying to upload a file to Onedrive using my REST API Source: single disk api documentation

I use OneDrive snippets for this, as the file size can be as huge as 5 GB or less than 1 KB (user dependent)

I am currently doing this using the POST-MAN Chrome extension to call APIs

How am i doing this?

  • Activated Access Token
  • Session created and retrieved download URL
  • Download a file using a PUT request as follows

The selected file I want to download (File size: 729676295 bytes) enter image description here

Added headers and sent a request and sent a request enter image description here Here is the result enter image description here

he says the maximum fragment size is 67108864 bytes, so I changed the value

content length: 67108864 and content range: bytes 0-67108863 / 729676295

but then I get this error message: The declared fragment length does not match the provided number of bytes enter image description here

Please help me figure out what I should convey in the area of ​​content and content.

Thank you very much for your attention.

+5
source share
2 answers

Finally, thanks to God, after 2 days of struggle, I found what was the problem.

There are a few points you need to keep in mind.

  • You need to split the file into equal parts and save it somewhere and download each of them at the same URL that you will receive after creating the session.
  • Content-Length should be the total number of bytes of the file that you upload to all fragment download requests.
  • Content-Range will look like this: 0- {fragmentLength-1} / {totalNumberOfBytesOfFile} (same as the length of the content), and from the next fragment Content-Range will be {uploadedBytes} - {uploadedBytes + nextSetOfBytes-1} / {totalNumberOfBytesOfFile}

Note. The next set of bytes should be the same as the previous one. Do not worry, because the last fragment may be different.

PS: Do not use the range of content that you get after successfully loading a fragment.

+3
source

enter image description here

{totalNumberOfBytesOfFile} does not match the length of the content; Content-Length are the bytes of the current fragment.

The image is an example for downloading a 4917 byte file.

+2
source

Source: https://habr.com/ru/post/1236319/


All Articles