WL.backgroundUpload (Windows Store app)
Makes a call to upload a file to Microsoft OneDrive.
Important
WL.backgroundUpload is supported only for use with Windows Store apps using JavaScript. If you are writing a web app, use WL.upload instead.
Parameters
properties
Required. A JSON object that contains the following properties, which are necessary to make the REST API call.
Name
Type
Description
Default Value
path
string
Required. The path to the file to upload.
None
file_name
string
Optional. The name of the file to upload.
None
file_input
Windows.Storage.StorageFile or File
Optional. The file input object to read the file from.
None
stream_input
Windows.Storage.Streams.IInputStream
Optional. The file input stream to read the file from.
None
overwrite
boolean or string
Optional. Indicates whether the uploaded file should overwrite an existing copy. Specify true or "true" to overwrite, false or "false" to not overwrite and for the WL.backgroundUpload method call to fail, or "rename" to not overwrite and enable OneDrive to assign a new name to the uploaded file.
"false"
callback
Optional. Specifies a callback function that is executed when the REST API call is complete. The callback function takes the API response object as a parameter. The response object exposes the data returned from the Live SDK, or if an error occurs, an error property that contains the error code.
Note
Although the callback parameter is still supported, we recommend that you use the Promise object instead, which is described later in this topic.
Return value
Returns a Promiseobject. For Windows Store apps using JavaScript, this object's then method accepts callback functions for onSuccess, onError, and onProgress to enable your code to handle a successful, failed, and in-progress call to the corresponding WL.backgroudUpload method, respectively.
Remarks
Note
Before calling the WL.backgroundUpload function, your code must call either the WL.init or WL.login function with, at minimum, the required scopes for uploading the corresponding file. If you don't do this, the call to the WL.backgroundUpload function may fail. Also, this requirement applies to each webpage's current session. Therefore, if your app contains multiple webpages, each webpage must follow this requirement.
Example
function uploadFile_onClick() {
var picker = setupOpenPicker();
var filePickOp = picker.pickSingleFileAsync().then(
function (file) {
WL.login({
scope: "wl.skydrive_update"
}).then(
function (response) {
WL.backgroundUpload({
path: "me/skydrive",
file_name: file.fileName,
file_input: file,
overwrite: "rename"
}).then(
function (response) {
document.getElementById("infoLabel").innerText = "Uploaded file.";
},
function (responseFailed) {
document.getElementById("infoLabel").innerText =
"Error calling API: " + responseFailed.error.message;
}
);
},
function (responseFailed) {
document.getElementById("infoLabel").innerText =
"Error signing in: " + responseFailed.error.message;
}
);
},
function (fileFailed) {
document.getElementById("infoLabel").innerText = "Cannot upload file.";
}
);
}
function setupOpenPicker() {
var openpicker = new Windows.Storage.Pickers.FileOpenPicker();
openpicker.fileTypeFilter.replaceAll(["*"]);
return openpicker;
}
Requirements
Library |
Wl.js |