Files: copy

Requires authorization

Creates a copy of the specified file. Try it now or see an example.


HTTP request



Parameter name Value Description
Path parameters
fileId string The ID of the file to copy.
Optional query parameters
convert boolean Whether to convert this file to the corresponding Google Docs format. (Default: false)
ocr boolean Whether to attempt OCR on .jpg, .png, .gif, or .pdf uploads. (Default: false)
ocrLanguage string If ocr is true, hints at the language to use. Valid values are BCP 47 codes.
pinned boolean Whether to pin the head revision of the new copy. A file can have a maximum of 200 pinned revisions. (Default: false)
supportsTeamDrives boolean Whether the requesting application supports Team Drives. (Default: false)
timedTextLanguage string The language of the timed text.
timedTextTrackName string The timed text track name.
visibility string The visibility of the new file. This parameter is only relevant when the source is not a native Google Doc and convert=false.

Acceptable values are:
  • "DEFAULT": The visibility of the new file is determined by the user's default visibility/sharing policies. (default)
  • "PRIVATE": The new file will be visible to only the owner.


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 with the following properties:

Property name Value Description Notes
Optional Properties
description string A short description of the file. writable
indexableText.text string The text to be indexed for this file. writable
labels.hidden boolean Deprecated. writable
labels.restricted boolean Whether viewers and commenters are prevented from downloading, printing, and copying this file. writable
labels.starred boolean Whether this file is starred by the user. writable
labels.trashed boolean Whether this file has been trashed. This label applies to all users accessing the file; however, only owners are allowed to see and untrash files. writable
labels.viewed boolean Whether this file has been viewed by this user. writable
lastViewedByMeDate datetime Last time this file was viewed by the user (formatted RFC 3339 timestamp). writable
markedViewedByMeDate datetime Deprecated. writable
modifiedDate datetime Last time this file was modified by anyone (formatted RFC 3339 timestamp). This is only mutable on update when the setModifiedDate parameter is set. writable
parents[] list Collection of parent folders which contain this file.

Setting this field will put the file in all of the provided folders. On insert, if no folders are provided, the file will be placed in the default root folder.

properties[] list The list of properties. writable
title string The title of this file. Note that for immutable items such as the top level folders of Team Drives, My Drive root folder, and Application Data folder the title is constant. writable
writersCanShare boolean Whether writers can share the document with other users. Not populated for Team Drive files. writable


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.


// ...

public class MyClass {

  // ...

   * Copy an existing file.
   * @param service Drive API service instance.
   * @param originFileId ID of the origin file to copy.
   * @param copyTitle Title of the copy.
   * @return The copied file if successful, {@code null} otherwise.
  private static File copyFile(Drive service, String originFileId,
      String copyTitle) {
    File copiedFile = new File();
    try {
      return service.files().copy(originFileId, copiedFile).execute();
    } catch (IOException e) {
      System.out.println("An error occurred: " + e);
    return null;

  // ...



Uses the .NET client library.

using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;

using System.Net;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Copy an existing file.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="originFileId">ID of the origin file to copy.</param>
  /// <param name="copyTitle">Title of the copy.</param>
  /// <returns>The copied file, null is returned if an API error occurred</returns>
  public static File CopyFile(DriveService service, String originFileId, String copyTitle) {
    File copiedFile = new File();
    copiedFile.Title = copyTitle;
    try {
      return service.Files.Copy(copiedFile, originFileId).Execute();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    return null;

  // ...



Uses the PHP client library.

 * Copy an existing file.
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $originFileId ID of the origin file to copy.
 * @param String $copyTitle Title of the copy.
 * @return DriveFile The copied file. NULL is returned if an API error occurred.
function copyFile($service, $originFileId, $copyTitle) {
  $copiedFile = new Google_Service_Drive_DriveFile();
  try {
    return $service->files->copy($originFileId, $copiedFile);
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  return NULL;


Uses the Python client library.

from apiclient import errors
# ...

def copy_file(service, origin_file_id, copy_title):
  """Copy an existing file.

    service: Drive API service instance.
    origin_file_id: ID of the origin file to copy.
    copy_title: Title of the copy.

    The copied file if successful, None otherwise.
  copied_file = {'title': copy_title}
    return service.files().copy(
        fileId=origin_file_id, body=copied_file).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None


Uses the JavaScript client library.

 * Copy an existing file.
 * @param {String} originFileId ID of the origin file to copy.
 * @param {String} copyTitle Title of the copy.
function copyFile(originFileId, copyTitle) {
  var body = {'title': copyTitle};
  var request ={
    'fileId': originFileId,
    'resource': body
  request.execute(function(resp) {
    console.log('Copy ID: ' +;


Uses the Go client library.

import (

// CopyFile copies a file setting a new title on the copy
func CopyFile(d *drive.Service, fileId string,
    title string) (*drive.File, error) {
  f := &drive.File{Title: title}
  r, err := d.Files.Copy(fileId, f).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return nil, err
  return r, nil


Uses the Objective-C client library.

#import "GTLDrive.h"
// ...

+ (void)copyFileWithService:(GTLServiceDrive *)service
               originFileId:(NSString *)originFileId
                  copyTitle:(NSString *)copyTitle
            completionBlock:(void (^)(GTLDriveFile *, NSError *))completionBlock {
  GTLDriveFile *copiedFile = [GTLDriveFile object];
  copiedFile.title = copyTitle;

  GTLQueryDrive *query =
    [GTLQueryDrive queryForFilesCopyWithObject:copiedFile fileId:originFileId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket, GTLDriveFile *file,
                            NSError *error) {
          if (error == nil) {
            completionBlock(file, nil);
          } else {
            NSLog(@"An error occurred: %@", error);
            completionBlock(nil, error);

// ...

Try it!

Use the APIs Explorer below to call this method on live data and see the response.

Send feedback about...

Drive REST API v2
Drive REST API v2