Skip to content

Latest commit

 

History

History
166 lines (114 loc) · 4.96 KB

File metadata and controls

166 lines (114 loc) · 4.96 KB
author spgraph-docs-team
ms.date 09/10/2017
title Upload small files
ms.localizationpriority high
ms.subservice sharepoint
description Provide the contents of a new file or update the contents of an existing file in a single API call.
doc_type apiPageType

Upload or replace the contents of a driveItem

Namespace: microsoft.graph

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 250 MB in size.

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

[!INCLUDE national-cloud-support]

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

[!INCLUDE permissions-table]

[!INCLUDE app-permissions]

HTTP request

To replace an existing item

PUT /drives/{drive-id}/items/{item-id}/content
PUT /groups/{group-id}/drive/items/{item-id}/content
PUT /me/drive/items/{item-id}/content
PUT /sites/{site-id}/drive/items/{item-id}/content
PUT /users/{user-id}/drive/items/{item-id}/content

To upload a new file

PUT /drives/{drive-id}/items/{parent-id}:/{filename}:/content
PUT /groups/{group-id}/drive/items/{parent-id}:/{filename}:/content
PUT /me/drive/items/{parent-id}:/{filename}:/content
PUT /sites/{site-id}/drive/items/{parent-id}:/{filename}:/content
PUT /users/{user-id}/drive/items/{parent-id}:/{filename}:/content

Request headers

Name Description
Authorization Bearer {token}. Required. Learn more about authentication and authorization.
Content-Type text/plain. Required.

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 or updated file.

Examples

Example 1: Upload a new file

Request

This example uploads the string "The contents of the file goes here." to a file in the signed-in user's drive under FolderA named FileB.txt.

PUT https://graph.microsoft.com/v1.0/me/drive/root:/FolderA/FileB.txt:/content
Content-Type: text/plain

The contents of the file goes here.

Response

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

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

{
  "id": "0123456789abc",
  "name": "FileB.txt",
  "size": 35,
  "file": { }
}

Example 2: Updating an existing file

Request

This example replaces the contents of a file with a known ID.

PUT https://graph.microsoft.com/v1.0/me/drive/items/{item-id}/content
Content-Type: text/plain

The contents of the file goes here.

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

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

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

{
  "id": "0123456789abc",
  "name": "FileB.txt",
  "size": 35,
  "file": { }
}

Error responses

See Error Responses for details about how errors are returned.