This guide explains how to create and manage files in Google Drive.
Create file
To create a file in Drive that contains no metadata or content,
use the
files.create
method with no
parameters. The file is given a
kind
of
drive.file
, an
id
, a
name
of
"Untitled", and a
mimeType
of
application/octet-stream
. The
uploadType
is
marked as required but defaults to
media
, so you don't actually have to supply
it.
For more information about Drive file limits, see
File and
folder limits
.
Metadata-only files contain no content. Metadata is data (such as
name
,
mimeType
, and
createdTime
) that describes the file. Fields like
name
are
user-agnostic and appear the same for each user, whereas fields such as
viewedByMeTime
contain user-specific values.
One example of a metadata-only file is a folder with the MIME type
application/vnd.google-apps.folder
. For more information, see
Create and
populate folders
. Another example is a shortcut that
points to another file on Drive with the MIME type
application/vnd.google-apps.shortcut
. For more information, see
Create a
shortcut to a Drive file
.
Manage thumbnail images
Thumbnails help users identify Drive files. Drive
can automatically generate thumbnails for common file types or you can provide a
thumbnail image generated by your app. For more information, see
Upload
thumbnails
.
Copy an existing file
To copy a file, and apply any requested updates, use the
files.copy
method. To find the
fileId
to
copy, use the
files.list
method.
Note that you need to use an appropriate
Drive API
scope
to authorize the
call. For more information on Drive scopes, see
Choose
Google Drive API scopes
.
Limits and considerations
As you prepare to copy files, take note of these limits and considerations:
Permissions
:
- The
copyRequiresWriterPermission
file restriction determines who can
copy the file. For more information, see
Prevent users from
downloading, printing, or copying your
file
.
- The
capabilities/canCopy
field of a
files
resource determines
whether the user can copy a file. For more information, see
Capabilities
.
- The user that created the copy owns the copied file. No other sharing
settings from the source file are replicated. If the copy is created in
a shared folder, it inherits the permissions of that folder.
- A copied file's ownership might change and the copy might not inherit
the original file's sharing settings. These settings might need to be
reset.
File management
:
- Some files, like
third-party
shortcuts
, can never be
copied.
- You can only copy a file into one parent folder. Specifying multiple
parents isn't supported. If the
parents
field isn't specified, the
file inherits any discoverable parents from the source file.
- Even though a folder is a type of file, you can't copy a folder.
Instead, create a destination folder and set the
parents
field of the
existing files to the destination folder. You can then delete the
original source folder.
- Unless a new filename is specified, the
files.copy
method produces a
file with the same name as the original.
- Excessive use of
files.copy
can lead to exceeding your
Drive API quota limits. For more information, see
Usage
limits
.
Here are a few next steps you might try: