Chunk download with OneDrive Rest API

偶尔善良 提交于 2019-12-12 01:14:45

问题


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


回答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.



来源:https://stackoverflow.com/questions/25972402/chunk-download-with-onedrive-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!