Upload or replace the contents of a driveItem

Important: APIs under the /beta version in Microsoft Graph are in preview and are subject to change. Use of these APIs in production applications is not supported.

The simple upload API allows you to provide the contents of a new file or update the contents of an existing file in a single API call. This method only supports files up to 4MB in size.

To upload large files see Upload large files with an upload session.

Prerequisites

One of the following scopes is required to execute this API:

  • Files.ReadWrite
  • Files.ReadWrite.All
  • Sites.ReadWrite.All

HTTP request

PUT /me/drive/items/{parent-id}:/{filename}:/content
PUT /me/drive/root:/{parent-path}/{filename}:/content
PUT /me/drive/items/{parent-id}/children/{filename}/content
PUT /groups/{id}/drive/items/{parent-id}/children/{filename}/content

Request body

The contents of the request body should be the binary stream of the file to be uploaded.

Response

If successful, this method returns a driveItem object in the response body for the newly created file.

Example

This example uploads a file by path to the signed-in user's OneDrive.

PUT /me/drive/root:/{item-path}:/content
Content-type: text/plain

The contents of the file goes here.
Response

The following example shows the response.

HTTP/1.1 201 Created
Content-Type: application/json

{
  "id": "0123456789abc",
  "name": "myfile.jpg",
  "size": 10191,
  "file": { }
}