Files: patch

Requires authorization

Updates file metadata and/or content. This method supports patch semantics. See an example.


HTTP Request

PATCH https://www.googleapis.com/drive/v1/files/id


Parameter Name Value Description
Required Parameters
id string The ID for the file in question.
Optional Parameters
newRevision boolean Whether a blob upload should create a new revision. If not set or false, the blob data in the current head revision will be replaced. If true, a new blob is created as head revision, and previous revisions are preserved (causing increased use of the user's data storage quota).
updateModifiedDate boolean Controls updating the modified date of the file. If true, the modified date will be updated to the current time, regardless of whether other changes are being made. If false, the modified date will only be updated to the current time if other changes are also being made (changing the title, for example).
updateViewedDate boolean Whether to update the view date after successfully updating the file.


This request requires authorization with at least one of the following scopes (read more about authentication and authorization).


Request Body

In the request body, supply a Files resource.


If successful, this method returns a Files resource in the response body.


Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).


Uses the Java client library

import com.google.api.services.drive.Drive;
import com.google.api.services.drive.Drive.Files;
import com.google.api.services.drive.model.File;

import java.io.IOException;
// ...

public class MyClass {

  // ...

   * Rename a file.
   * @param service Drive API service instance.
   * @param fileId ID of the file to rename.
   * @param newTitle New title for the file.
   * @return Updated file metadata if successful, {@code null} otherwise.
  private static File renameFile(Drive service, String fileId, String newTitle) {
    try {
      File file = new File();

      // Rename the file.
      Files.Patch patchRequest = service.files().patch(fileId, file);

      File updatedFile = patchRequest.execute();
      return updatedFile;
    } catch (IOException e) {
      System.out.println("An error occurred: " + e);
      return null;

  // ...


Uses the .NET client library

using Google.Apis.Drive.v1;
using Google.Apis.Drive.v1.Data;

// ...

public class MyClass {

  // ...

  /// <summary>
  /// Rename a file.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to rename.</param>
  /// <param name="newTitle">New title for the file.</param>
  /// <returns>Updated file metadata, null is returned if an API error occurred.</returns>
  private static File renameFile(DriveService service, String fileId, String newTitle) {
      try {
          File file = new File();
          file.Title = newTitle;

          // Rename the file.
          FilesResource.PatchRequest request = service.Files.Patch(file, fileId);
          request.FieldsMask = "title";
          File updatedFile = request.Execute();

          return updatedFile;
      } catch (Exception e) {
          Console.WriteLine("An error occurred: " + e.Message);
          return null;




Uses the PHP client library

 * Rename a file.
 * @param apiDriveService $service Drive API service instance.
 * @param string $fileId ID of the file to rename.
 * @param string $newTitle New title for the file.
 * @return DriveFile The updated file. NULL is returned if an API error occurred.
function renameFile($service, $fileId, $newTitle) {
  try {
    $file = new DriveFile();

    $updatedFile = $service->files->patch($fileId, $file, array(
      'fields' => 'title'

    return $updatedFile;
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();


Uses the Python client library

from apiclient import errors
# ...

def rename_file(service, file_id, new_title):
  """Rename a file.

    service: Drive API service instance.
    file_id: ID of the file to rename.
    new_title: New title for the file.
    Updated file metadata if successful, None otherwise.
    file = {'title': new_title}

    # Rename the file.
    updated_file = service.files().patch(

    return updated_file
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
    return None


Uses the Ruby client library

# Rename a file
# @param [Google::APIClient] client
#   Authorized client instance
# @param [String] file_id
#   ID of file to update
# @param [String] title
#   New title of file
# @return [Google::APIClient::Schema::Drive::V1::File]
#   File if update, nil otherwise
def rename_file(client, title)
  drive = client.discovered_api('drive', 'v1')
  result = client.execute(
    :api_method => drive.files.patch,
    :body_object => { 'title' => title })
  if result.status == 200
    return result.data
  puts "An error occurred: #{result.data['error']['message']}"
  return nil

Send feedback about...