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

Dav*_*ave 7 javascript mobile ios onedrive

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

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

Nav*_*uja 0

要从手机访问手机的相机,您可以使用输入标签,如下所示:

 <input type="file" accept="image/*" capture="camera">
Run Code Online (Sandbox Code Playgroud)

现在要上传文件,您可以使用 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>
Run Code Online (Sandbox Code Playgroud)

其中 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 */ }
}
Run Code Online (Sandbox Code Playgroud)

您的成功响应将包含 OneDrive 上传文件的 URL,该 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/..." }
        }
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅:https://learn.microsoft.com/en-us/onedrive/developer/controls/file-pickers/js-v72/save-file