【问题标题】:Create downloadable link and Preview File for OneDrive DriveItem为 OneDrive DriveItem 创建可下载链接和预览文件
【发布时间】:2018-05-08 07:16:01
【问题描述】:

我一直在尝试为 OneDrive 生成​​一个公共的可下载 URL 对于 Business 和 SharePoint DriveItem 对象,使用 /createLink api

curl \
  -X POST \
  -d '{"type":"view","scope":"anonymous"}' \
  -H 'Authorization: bearer xxx_Access_Token_xxx' \
  -H 'Content-Type: application/json' \
  "https://graph.microsoft.com/v1.0/drive/items/<item-id>/createLink"

上述调用返回 JSON 结果,其中 body.link.webUrl (https://my.sharepoint.com/:u:/g/XXXXrKmGKlXXXXXXXXXXsq0Bh3x4TTXXXXXXXXXXXXXXXXX) 是可共享的 URL。但是,此链接不直接包含对文件的引用。

根据this 评论,将download=1 作为查询字符串参数附加到生成的共享URL 将允许用户直接打开原始文件。但我找不到任何支持这种行为的文档。

可以吗

  • 直接下载文件。
  • 将公共 URL 用作 img 标记的 src 属性。

【问题讨论】:

    标签: microsoft-graph-api onedrive


    【解决方案1】:

    您可以关注OneDrive的官方文档

    您必须将下面的代码行放在 IProgressCallback 的成功字段中。这里 ItemId 是“上传项目的 ID”。

    String itemId = result.id;
                TestBase testBase = new TestBase(xdata.getinstance().getSetting(config.onedriveaccesstoken));
                AsyncTask<Void, Void, Void>  downloadfileonedrive = new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(final Void... params) {
                        com.microsoft.graph.models.extensions.Permission response = testBase.graphClient
                            .me()
                            .drive()
                            .items(itemId)
                            .createLink("edit", "anonymous")
                            .buildRequest().post();        
                         Log.e("Sharable link : ", ""+response);     
    
                         try {
    
                              String sharabalelink = new JSONObject(response.getRawObject().getAsJsonObject("link").toString()).getString("webUrl");
    
                          } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    return null;
                }
                @Override
                protected void onCancelled() {
                     super.onCancelled();
                }};
                downloadfileonedrive.execute();
    

    【讨论】:

      猜你喜欢
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      • 2019-02-05
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多