Export (0) Print
Expand All

WL.upload

Last modified: March 13, 2015

Makes a call to upload a file to Microsoft OneDrive.

Important note Important

WL.upload is supported only for use with web apps. If you are writing a Windows Store app using JavaScript, use WL.backgroundUpload 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

    element

    string

    Required. The id attribute of the <input> tag containing info about the file to upload.

    None

    overwrite

    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.upload 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 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 Promise object. This object's then method provides the onSuccess, onError, and onProgress parameters to enable your code to handle a successful, failed, and in-progress call to the corresponding WL.upload method, respectively; however, the onProgress parameter applies to newer web browsers such as Internet Explorer 10 only.

Examples

<form>
    <input id="file" name="file" type="file" />
</form>
<button onclick="uploadFile()">Save file directly (calling WL.upload)</button>
function uploadFile() {
    WL.login({
        scope: "wl.skydrive_update"
    }).then(
        function (response) {
            WL.upload({
                path: "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!170",
                element: "file",
                overwrite: "rename"
            }).then(
                function (response) {
                    document.getElementById("info").innerText =
                        "File uploaded.";
                },
                function (responseFailed) {
                    document.getElementById("info").innerText =
                        "Error uploading file: " + responseFailed.error.message;
                }
            );                    
        },
        function (responseFailed) {
            document.getElementById("info").innerText =
                "Error signing in: " + responseFailed.error.message;
        }
    );
}

Requirements

Library

Wl.js

Show:
© 2015 Microsoft