使用OneDrive Rest API进行块下载

问题描述:

这是我第一次在StackOverflow上写。我的问题是以下。

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

我试图写一个基于cpprest sdk CasaBlanca项目的OneDrive C ++ API:

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

https://casablanca.codeplex.com/

具体来说,我目前正在对OneDrive文件执行读取操作。

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()

此代码基本上是在计算机上下载整个文件(file_id是我想要下载的文件的ID)。当然,我可以从文件中提取输入流,并使用它来读取文件。

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).

然后,我的问题是:

可以使用OneDrive REST + cpprest的存储在OneDrive上的文件。我发现以块的形式上传文件似乎不可能( OneDrive的分块上传(可恢复上传))。这是真的也下载?

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?

提前感谢您的时间。

最好的问候,

Giuseppe

OneDrive支持字节范围读取。因此,您应该可以通过添加Range标头来请求任何大小的块。

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

例如,

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

这将获取文件的第一个KB。

This will fetch the first KB of the file.