Files
class Files extends Resource (View source)
The "files" collection of methods.
Typical usage is:
$driveService = new Google\Service\Drive(...);
$files = $driveService->files;
Methods
Creates a new file. This method supports an upload URI and accepts uploaded
media with the following characteristics: - Maximum file size: 5,120 GB -
Accepted Media MIME types:`Note: Specify a valid MIME type, rather than the literal
value. The literal
is only used to indicate that any valid MIME type can be uploaded. For more information on uploading files, see [Upload file data](/drive/api/guides/manage-uploads). Apps creating shortcuts with
files.createmust specify the MIME type
application/vnd.google-
apps.shortcut. Apps should specify a file extension in the
nameproperty when inserting files with the API. For example, an operation to insert a JPEG file should specify something like
"name": "cat.jpg"` in the metadata.
Permanently deletes a file owned by the user without moving it to the trash.
Permanently deletes all of the user's trashed files. (files.emptyTrash)
Exports a Google Workspace document to the requested MIME type and returns exported byte content. Note that the exported content is limited to 10MB.
Generates a set of file IDs which can be provided in create or copy requests.
Gets a file's metadata or content by ID. If you provide the URL parameter
alt=media
, then the response includes the file contents in the response
body. Downloading content with alt=media
only works if the file is stored
in Drive. To download Google Docs, Sheets, and Slides use
files.export
instead. For more
information, see Download & export files. (files.get)
Lists the user's files. This method accepts the q
parameter, which is a
search query combining one or more search terms. For more information, see
the Search for files & folders guide.
Lists the labels on a file. (files.listLabels)
Modifies the set of labels applied to a file. Returns a list of the labels that were added or modified. (files.modifyLabels)
Updates a file's metadata and/or content. When calling this method, only
populate fields in the request that you want to modify. When updating fields,
some fields might be changed automatically, such as modifiedDate
. This
method supports patch semantics. This method supports an upload URI and
accepts uploaded media with the following characteristics: - Maximum file
size: 5,120 GB - Accepted Media MIME types:`Note: Specify a valid MIME type, rather than the literal
value. The literal
` is only used to
indicate that any valid MIME type can be uploaded. For more information on
uploading files, see Upload file data.
Details
DriveFile
copy(string $fileId, DriveFile $postBody, array $optParams = [])
Creates a copy of a file and applies any requested updates with patch semantics. (files.copy)
DriveFile
create(DriveFile $postBody, array $optParams = [])
Creates a new file. This method supports an upload URI and accepts uploaded
media with the following characteristics: - Maximum file size: 5,120 GB -
Accepted Media MIME types:`Note: Specify a valid MIME type, rather than the literal
value. The literal
is only used to indicate that any valid MIME type can be uploaded. For more information on uploading files, see [Upload file data](/drive/api/guides/manage-uploads). Apps creating shortcuts with
files.createmust specify the MIME type
application/vnd.google-
apps.shortcut. Apps should specify a file extension in the
nameproperty when inserting files with the API. For example, an operation to insert a JPEG file should specify something like
"name": "cat.jpg"` in the metadata.
Subsequent GET
requests include the read-only fileExtension
property
populated with the extension originally specified in the title
property.
When a Google Drive user requests to download a file, or when the file is
downloaded through the sync client, Drive builds a full filename (with
extension) based on the title. In cases where the extension is missing, Drive
attempts to determine the extension based on the file's MIME type.
(files.create)
delete(string $fileId, array $optParams = [])
Permanently deletes a file owned by the user without moving it to the trash.
If the file belongs to a shared drive, the user must be an organizer
on the
parent folder. If the target is a folder, all descendants owned by the user
are also deleted. (files.delete)
emptyTrash(array $optParams = [])
Permanently deletes all of the user's trashed files. (files.emptyTrash)
export(string $fileId, string $mimeType, array $optParams = [])
Exports a Google Workspace document to the requested MIME type and returns exported byte content. Note that the exported content is limited to 10MB.
(files.export)
GeneratedIds
generateIds(array $optParams = [])
Generates a set of file IDs which can be provided in create or copy requests.
(files.generateIds)
DriveFile
get(string $fileId, array $optParams = [])
Gets a file's metadata or content by ID. If you provide the URL parameter
alt=media
, then the response includes the file contents in the response
body. Downloading content with alt=media
only works if the file is stored
in Drive. To download Google Docs, Sheets, and Slides use
files.export
instead. For more
information, see Download & export files. (files.get)
FileList
listFiles(array $optParams = [])
Lists the user's files. This method accepts the q
parameter, which is a
search query combining one or more search terms. For more information, see
the Search for files & folders guide.
Note: This method returns all files by default, including trashed files.
If you don't want trashed files to appear in the list, use the
trashed=false
query parameter to remove trashed files from the results.
(files.listFiles)
LabelList
listLabels(string $fileId, array $optParams = [])
Lists the labels on a file. (files.listLabels)
ModifyLabelsResponse
modifyLabels(string $fileId, ModifyLabelsRequest $postBody, array $optParams = [])
Modifies the set of labels applied to a file. Returns a list of the labels that were added or modified. (files.modifyLabels)
DriveFile
update(string $fileId, DriveFile $postBody, array $optParams = [])
Updates a file's metadata and/or content. When calling this method, only
populate fields in the request that you want to modify. When updating fields,
some fields might be changed automatically, such as modifiedDate
. This
method supports patch semantics. This method supports an upload URI and
accepts uploaded media with the following characteristics: - Maximum file
size: 5,120 GB - Accepted Media MIME types:`Note: Specify a valid MIME type, rather than the literal
value. The literal
` is only used to
indicate that any valid MIME type can be uploaded. For more information on
uploading files, see Upload file data.
(files.update)