class Files extends Resource (View source)

The "files" collection of methods.

Typical usage is:

 $driveService = new Google\Service\Drive(...);
 $files = $driveService->files;

Methods

copy(string $fileId, DriveFile $postBody, array $optParams = [])

Creates a copy of a file and applies any requested updates with patch semantics. (files.copy)

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 literalvalue. The literalis 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 withfiles.createmust specify the MIME typeapplication/vnd.google- apps.shortcut. Apps should specify a file extension in thenameproperty 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.

delete(string $fileId, array $optParams = [])

Permanently deletes a file owned by the user without moving it to the trash.

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.

generateIds(array $optParams = [])

Generates a set of file IDs which can be provided in create or copy requests.

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)

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.

listLabels(string $fileId, array $optParams = [])

Lists the labels on a file. (files.listLabels)

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)

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 literalvalue. 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.

watch(string $fileId, Channel $postBody, array $optParams = [])

Subscribes to changes to a file. (files.watch)

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)

Parameters

string $fileId

The ID of the file.

DriveFile $postBody
array $optParams

Optional parameters.

Return Value

DriveFile

Exceptions

Exception

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 literalvalue. The literalis 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 withfiles.createmust specify the MIME typeapplication/vnd.google- apps.shortcut. Apps should specify a file extension in thenameproperty 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)

Parameters

DriveFile $postBody
array $optParams

Optional parameters.

Return Value

DriveFile

Exceptions

Exception

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)

Parameters

string $fileId

The ID of the file.

array $optParams

Optional parameters.

Exceptions

Exception

emptyTrash(array $optParams = [])

Permanently deletes all of the user's trashed files. (files.emptyTrash)

Parameters

array $optParams

Optional parameters.

Exceptions

Exception

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)

Parameters

string $fileId

The ID of the file.

string $mimeType

Required. The MIME type of the format requested for this export.

array $optParams

Optional parameters.

Exceptions

Exception

GeneratedIds generateIds(array $optParams = [])

Generates a set of file IDs which can be provided in create or copy requests.

(files.generateIds)

Parameters

array $optParams

Optional parameters.

Return Value

GeneratedIds

Exceptions

Exception

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)

Parameters

string $fileId

The ID of the file.

array $optParams

Optional parameters.

Return Value

DriveFile

Exceptions

Exception

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)

Parameters

array $optParams

Optional parameters.

Return Value

FileList

Exceptions

Exception

LabelList listLabels(string $fileId, array $optParams = [])

Lists the labels on a file. (files.listLabels)

Parameters

string $fileId

The ID for the file.

array $optParams

Optional parameters.

Return Value

LabelList

Exceptions

Exception

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)

Parameters

string $fileId

The ID of the file to which the labels belong.

ModifyLabelsRequest $postBody
array $optParams

Optional parameters.

Return Value

ModifyLabelsResponse

Exceptions

Exception

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 literalvalue. 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)

Parameters

string $fileId

The ID of the file.

DriveFile $postBody
array $optParams

Optional parameters.

Return Value

DriveFile

Exceptions

Exception

Channel watch(string $fileId, Channel $postBody, array $optParams = [])

Subscribes to changes to a file. (files.watch)

Parameters

string $fileId

The ID of the file.

Channel $postBody
array $optParams

Optional parameters.

Return Value

Channel

Exceptions

Exception