从SharePoint下载文件 [英] Download file from SharePoint

查看:237
本文介绍了从SharePoint下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SharePoint的REST API查询公司用户的Office 365 SharePoint网站中托管的文件.

I'm using the REST APIs of SharePoint to query the files hosted inside a corporate user's Office 365 SharePoint site.

我已使用OAuth对用户进行身份验证并授权了该应用,如下所述: http://msdn.microsoft.com/en-us/library/azure/dn645542.aspx

I have used OAuth to authenticate the user and authorize the the app, as described here: http://msdn.microsoft.com/en-us/library/azure/dn645542.aspx

我能够通过GET请求成功查询API: https://XXXXXXX.sharepoint.com/sites/xxxxx/xxxxx/myfoldername /_api/文件 (您所期望的作为Authorization标头的请求设置为'Bearer'.)

I am able to successfully query the API with a GET request on: https://XXXXXXX.sharepoint.com/sites/xxxxx/xxxxx/myfoldername/_api/files (the request as the Authorization header set to 'Bearer ', as you'd expect.)

上面的查询为我提供了以下JSON结果:

The above query gives me the following JSON result:

{
    "odata.metadata" = "https://xxxxxxxxx.sharepoint.com/sites/xxxxxxxxx/xxxxxxxxx/myfoldername/_api/$metadata#SP.ApiData.Files";
    value =     ( 
                {
            CreatedBy =             {
                Id = 1;
                Name = "Test";
                Puid = xxxxx;
            };
            ETag = "\"{hsdglksjfldkasnfldasknk},4\"";
            Id = JKLBbiuuu908yYHhh89YBn9n9ynynYUN;
            LastModifiedBy =             {
                Id = 1;
                Name = "XXXXX";
                Puid = XXXXXXXXXXX;
            };
            Name = "videofile.wmv";
            Size = 56492358;
            TimeCreated = "2013-09-23T05:16:44Z";
            TimeLastModified = "2013-09-23T05:28:42Z";
            Url = "https://xxxxxxxxx.sharepoint.com/sites/xxxxxxxxx/xxxxxxxxx/myfoldername/Shared Documents/videofile.wmv";
            "odata.editLink" = "Web/Lists(guid’9568472598-2c28-489BF2-a1ae-kfjdasfkjb)/files(‘jkbvasdjfbakfndasnMNBBAMnsaldfan)";
            "odata.id" = "https://xxxxxxxxx.sharepoint.com/sites/xxxxxxxxx/xxxxxxxxx/myfoldername/_api/Web/Lists(guid’987795-gfkjhghs-ty42398yhfo’)/files('jkbvasdjfbakfndasnMNBBAMnsaldfan')";
            "odata.type" = "MS.FileServices.File";
        })
}

(请记住,上面的内容实际上不是JSON,而是从JSON解析器输出的文本)

(Bear in mind the above is not actually JSON, but text output from a JSON parser)

在上面的结果中,我在value部分中得到了一个文件数组.为了说明起见,我将此阵列缩减为一个项目.

In the result above, I get an array of files inside the value part. I have cut this array down to one item for illustrative purposes.

您将看到每个项目代表文件的元数据.有一个名为Url的属性.然后,我用它来尝试下载文件.我创建一个HTTP请求,在Authorization标头后附加Bearer <access_token>,但是,响应始终是HTTP 401 UNAUTHORIZED.

You'll see each item represents a file's meta data. There's a property called Url; I then use this to attempt to download the file. I create an HTTP request, append the Authorization header with Bearer <access_token>, however, the response is always an HTTP 401 UNAUTHORIZED.

请注意:我正在编写的软件实际上是使用AFNetworking 2的AFHTTPRequestOperationManager在Objective-C中进行的.

Please note: the software I'm writing is actually in Objective-C using AFNetworking 2's AFHTTPRequestOperationManager.

有人知道我可以如何实际下载文件吗?我已经在文档中看到了对某些名为"contentUrl"的属性的引用,但未提供此属性.

Does anyone know how I can actually download the file? I have seen references to some property called 'contentUrl' in the docs, but this property is not supplied.

谢谢 克里斯(Kris)

thanks Kris

推荐答案

您是否正在使用API​​的v1?从您的端点看来,您似乎正在使用预览(v1已于2周前发布;我们的文档页面上可能仍然有过时的参考,如果您遇到任何问题,请告知我们)

Are you using the v1 of the API? From your endpoint it seems like you're using preview (v1 was released 2 weeks ago; we might still have outdated references on our documentation pages, please let us know if you come across any)

示例:

获取https://{tenant} .sharepoint.com/{site-path}/_api/v1.0/Files/{file-id}/content

GET https://{tenant}.sharepoint.com/{site-path}/_api/v1.0/Files/{file-id}/content

这是文档部分的URL,向您显示如何下载文件:

This is the URL of the documentation section that shows you how to download a file: http://msdn.microsoft.com/en-us/office/office365/api/files-rest-operations#FileresourceDownloadafile

让我知道您是否还有其他问题.

Let me know if you have any other issues.

这篇关于从SharePoint下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆