通过JavaScript / Web应用程序在设备上管理OneDrive

时间:2017-09-25 21:30:05

标签: javascript ios mobile onedrive

是否可能从网站上将OneDrive导向用户设备(iPad)以捕获照片并将其存储在特定文件夹中?是否可以在用户的​​设备上引导OneDrive以相同的方式创建文件夹?

用例基本上我们希望Web应用程序控制工作流程,但将照片捕获和异步上载外包给OneDrive。但我们知道照片的位置以及它们的名称,因此我们可以在完成上传后将它们下载到我们的服务器上,并在云中提供。

1 个答案:

答案 0 :(得分:0)

要从移动设备访问移动相机,您可以使用以下输入标签:

 <input type="file" accept="image/*" capture="camera">

现在要上传文件,你可以像这样使用OneDrive JS SDK:

<script type="text/javascript" src="https://js.live.net/v7.2/OneDrive.js"></script>
<script type="text/javascript">
  function launchSaveToOneDrive() {
    var odOptions = { /* ... specify the desired options ... */ };
    OneDrive.save(odOptions);
  }
</script>
<input type="file" id="fileUploadControl" name="fileUploadControl" accept="image/*" capture="camera">

<button onclick="launchSaveToOneDrive">Save to OneDrive</button>

其中odOptions将如下所示:

var odOptions = {
  clientId: "INSERT-APP-ID-HERE",
  action: "save",
  sourceInputElementId: "fileUploadControl",
  sourceUri: "",
  fileName: "file.txt",
  openInNewWindow: true,
  advanced: {},
  success: function(files) { /* success handler */ },
  progress: function(p) { /* progress handler */ },
  cancel: function() { /* cancel handler */ },
  error: function(e) { /* error handler */ }
}

您的成功将响应将具有OneDrive上传文件的URL,该文件将作为参数传递给成功回调。

{
  "value": [
    {
      "id": "123456",
      "name": "document1.docx",
      "size": 12340,
      "@content.downloadUrl": "https://contoso-my.sharepoint.com/download.aspx?guid=1231231231a",
      "webUrl": "https://cotoso-my.sharepoint.com/personal/user_contoso_com/documents/document1.docx",
      "thumbnails": [
        {
          "id": "0",
          "small": { "url": "https://sn3302files.onedrive.live.com/..." },
          "medium": { "url": "https://sn3302files.onedrive.live.com/..." },
          "large": { "url": "https://sn3302files.onedrive.live.com/..." }
        }
      ]
    }
  ]
}

有关详情,请参阅:https://docs.microsoft.com/en-us/onedrive/developer/controls/file-pickers/js-v72/save-file