Directing OneDrive on a device via JavaScript/web app

Viewed 870

Is it possibly, from a website, to direct OneDrive on a user's device (iPad) to capture a photo and store it in a specific folder? Is it possible to direct OneDrive on a user's device to create a folder in the same manner?

The use case is basically we want the web application to control workflow, but outsource the photo capturing and asynchronous uploading of photos to OneDrive. But we know where the photos are and what they're named, so we can download them onto our server later when they have finished uploading and are available in the cloud.

1 Answers

For accessing mobile's camera from mobile, you can use input tag as following:

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

Now to upload the file you can use OneDrive JS SDK like this:

<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>

where odOptions will look like this:

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 */ }
}

Your success will response will have the URL of OneDrive uploaded file which will be passed to success callback as param.

{
  "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/..." }
        }
      ]
    }
  ]
}

For more see: https://docs.microsoft.com/en-us/onedrive/developer/controls/file-pickers/js-v72/save-file)

Related