ARH*_*ARH 5 c# windows-phone-8 onedrive
我希望从One Drive下载公共文件夹中的文件,但它不下载文件.这是场景:
在公共文件夹中,我有另一个文件夹,其中包含多个文件,可以广泛访问.出于测试目的,我已经共享了公共文件夹中的所有文件(如果它是正确的共享方式,我不会这样做).
我BackgroundTransferRequest用以下代码下载文件:
string filePathToDownload = string.Empty, fileName = "111.mp3";
filePathToDownload = "http://1drv.ms/1z9XlW6";
Uri transferUri = new Uri(Uri.EscapeUriString(filePathToDownload), UriKind.RelativeOrAbsolute);
BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);
transferRequest.Method = "GET";
transferRequest.TransferPreferences = TransferPreferences.AllowCellularAndBattery;
Uri downloadUri = new Uri(DataSource.TEMPDOWNLOADLOCATION + fileName, UriKind.RelativeOrAbsolute);
transferRequest.DownloadLocation = downloadUri;
transferRequest.Tag = fileName;
Run Code Online (Sandbox Code Playgroud)
该文件为300Kb,但这仅下载6 Kb.
如何从上面的链接(其中任何一个)直接下载文件?
谢谢!
Mic*_*ael 11
如果您在网址中替换单词redir,download则会获得原始文件而不是网页,即
https://onedrive.live.com/download?resid=DBBC281099F4FE69%21646
基本上,你不能.这些链接是指向显示您共享文件的Web内容的链接.如果您的方案不介意要求用户登录OneDrive,则可以使用Live SDK访问这些文件.
要从Live SDK访问公用文件夹,您需要使用Live SDK获取公用文件夹的文件夹ID,或者将您复制的URL中的ID转换为Live SDK使用的格式:
folder.<user-id>.<folder-resid>
Run Code Online (Sandbox Code Playgroud)
!之前的部分在哪里!通常,您不应构造ID,因为将来ID可能会更改,而您应该从服务中检索ID.但是,使用您粘贴的URL,ID将为:
folder.DBBC281099F4FE69.DBBC281099F4FE69!646
Run Code Online (Sandbox Code Playgroud)
这将允许你打电话
https://apis.live.net:443/v5.0/folder.DBBC281099F4FE69.DBBC281099F4FE69!646/files?access_token=<valid_token>
Run Code Online (Sandbox Code Playgroud)
并检索各个文件的ID,然后您可以通过Live SDK下载这些详细信息:http://msdn.microsoft.com/en-US/library/dn659726.aspx#download_a_file