Files and folders contain metadata that describes them, which includes:
- The title of the file or folder
- The MIME type of the file or folder
- Whether the file or folder is starred
- Whether the file is editable
- Whether the file or folder is trashed
Metadata is encapsulated in the Metadata
class. The metadata is fetched for a
DriveResource
by calling the
DriveResourceClient.getMetadata
method.
The metadata may be set or changed when creating or updating a file by using a
MetadataChangeSet
, setting the
appropriate values, and then calling the
DriveResourceClient.updateMetadata
method.
You can also update the metadata with the file contents to commit concurrent or related changes atomically. For example, if a file's metadata also describes the contents, this avoids issues with inconsistent data if the metadata and contents are updated in separate requests and one of those requests fails.
Custom properties
Custom properties allow arbitrary metadata to be associated with a
DriveResource
in the form of key-value pairs. You can set custom properties
as public so that other applications can see them or as private so that only
the application that created the custom property can see it.
You can also query files, filtering on custom properties.
The following table lists the limits to adding custom properties to a resource:
Limit per resource | Maximum |
---|---|
Public custom properties | 30 |
Private custom properties per app | 30 |
Total custom properties | 100 |
Custom property length (key + value) | 124 bytes (UTF-8 encoding) |
Insert or update custom properties
When inserting or updating a custom property, you must create a
CustomPropertyKey
that identifies the custom property. You define a
CustomPropertyKey
by its custom property name and its visibility,
public or private. You can then use the
MetadataChangeSet.Builder.setCustomProperty
method with the
CustomPropertyKey
and the intended value of the custom property.
Delete custom properties
You can delete a custom property by using the
MetadataChangeSet.Builder.deleteCustomProperty
method and passing it the
appropriate CustomPropertyKey
. Your application can delete any custom property
visible to it, such as public custom properties and private custom
properties created by your application.