Downloading and uploading files on OneDrive (REST)

Your apps can use Live SDK REST API to download or upload files on Microsoft OneDrive.

In this article
Upload a file
Download a file
Update a file


We assume that the user has already signed in and consented to the wl.skydrive scope for reading file or folder properties. If you have not added user sign-in to your apps, see Signing users in with REST.

We assume that you are familiar with the REST API and JSON.

Upload a file

To add contents for an existing file, photo, video, or audio, use PUT or POST, depending on your platform's recommended approach. You can upload file sizes up to 100 megabytes.


On platforms that support the PUT request, PUT should be used to upload files to OneDrive when possible to avoid errors that can occur when POST is used.

This example uses PUT.


Hello, World!

If you're using POST as shown here, you must format the request as multipart/form-data. You provide the file to upload in a multipart section, while you provide the file name in the Content-Disposition header's filename parameter. For more info, see RFC 2388. Note that only one multipart section is supported in the body of the request.

Also, you can use any of these.

  • me/skydrive/files

  • FOLDER_ID/files, where FOLDER_ID is the ID of the parent folder.

  • The value of the upload_location structure for the folder to which the file, photo, video, or audio will be uploaded.


Content-Type: multipart/form-data; boundary=A300x

Content-Disposition: form-data; name="file"; filename="HelloWorld.txt"
Content-Type: application/octet-stream

Hello, World!

You can instruct OneDrive to notify the web browser when the upload finishes. You can also attach a unique identifier to each upload request so that you can identify a particular file if you are uploading multiple files in quick succession. To do this, use a POST multipart/form-data request, like this. Replace the folder ID with your target folder ID; replace the state query-string parameter value with your unique identifier; and replace the redirect_uri parameter with the path to your callback page.


The domain portion of the path must match the redirect domain that you specified in the Live SDK app management site for the corresponding client ID.


Content-Type: multipart/form-data; boundary=AaB03x

Content-Disposition: form-data; name="file"; filename="MyNewFile.txt"
Content-Type: text/plain

These are the contents of my new file.

OneDrive returns HTML-formatted code similar to the following.

        <script type="text/javascript">
            window.location = "!";

When decoded, the result response parameter is similar to this.

    "id": "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!184",
    "source": ",Default/MyNewFile.txt"


By default, the file, photo, video, or audio with the same name will be overwritten, if it already exists. You can add an overwrite query-string parameter with a value of false to not overwrite the existing file, photo, video, or audio. Or you can add an overwrite query-string parameter of ChooseNewName if you want to upload a duplicate copy of the file but let OneDrive choose a new file name for the uploaded file.

Before uploading a file, have your app check to make sure that there is enough available OneDrive storage space by making a GET call to USER_ID/skydrive/quota. For example, your app could get the size of the file in bytes and then compare it to the number of available storage bytes returned in the OneDrive quota call. For more info, see Get a user's total and remaining OneDrive storage quota.

If your app tries to upload the file when there's not enough available OneDrive storage space, the upload request will fail and OneDrive will return the following error.

    "error": {
        "code": "resource_quota_exceeded", 
        "message": "The user has reached his or her storage quota limit."

Download a file

Users can get the contents of a file, photo, video, or audio. The wl.skydrive scope is required.


You can instruct the user's web browser to prompt the user to save the file that's downloading instead of having the browser try to download and display the file directly in its own window. To do this, add the download=true query-string parameter after /content (for example, FILE_ID/content?download=true). This call adds the Content-Disposition: attachment header to the response.


To get a download link to the contents of a file, photo, video, or audio, use code like this.


Update a file

To change contents for an existing file, photo, video, or audio, use Upload a file, and append overwrite=true.


This topic showed you how you can let users download or upload files on OneDrive. Next, see Move, copy, create, or delete a file or folder (REST), to let your users perform other file or folder taks on OneDrive.