0

this is the first time I write on StackOverflow. My question is the following.

I am trying to write a OneDrive C++ API based on the cpprest sdk CasaBlanca project:

https://casablanca.codeplex.com/

In particular, I am currently implementing read operations on OneDrive files.

Actually, I have been able to download a whole file with the following code:

http_client api(U("https://apis.live.net/v5.0/"), m_http_config);

api.request(methods::GET, file_id +L"/content" ).then([=](http_response response){
    return response.body();
}).then([=]( istream is){
    streambuf<uint8_t> rwbuf = file_buffer<uint8_t>::open(L"test.txt").get();
    is.read_to_end(rwbuf).get();
    rwbuf.close();
}).wait()

This code is basically downloading the whole file on the computer (file_id is the id of the file I am trying to download). Of course, I can extract an inputstream from the file and using it to read the file.

However, this could give me issues if the file is big. What I had in mind was to download a part of the file while the caller was reading it (and caching that part if he came back).

Then, my question would be:

Is it possible, using the OneDrive REST + cpprest downloading a part of a file stored on OneDrive. I have found that uploading files in chunks seems apparently not possible (Chunked upload (resumable upload) for OneDrive?). Is this true also for the download?

Thank you in advance for your time.

Best regards,

Giuseppe

Community
  • 1
  • 1

1 Answers1

1

OneDrive supports byte range reads. And so you should be able to request chunks of whatever size you want by adding a Range header.

For example,

GET /v5.0/<fileid>/content
Range: bytes=0-1023

This will fetch the first KB of the file.

Brad
  • 4,089
  • 2
  • 16
  • 26
  • Thank you for that! As far as you know, is also possible to specify those headers for the upload of a file? – Giuseppe Rossini Sep 24 '14 at 10:29
  • Range is meant only HTTP retrieval requests such as what you're doing above. Theoretically, the Content-Range header could be used to facilitate a chunked upload mechanism, however as you found from another answer OneDrive does NOT currently support such a semantic. – Brad Sep 24 '14 at 18:22
  • There is now some documentation that describes how a chunked upload could work against OneDrive. Have a read of https://gist.github.com/rgregg/37ba8929768a62131e85 and see if it works for you scenario – Brad Dec 16 '14 at 17:41