Third-party shortcuts are files that link to files on other, external, storage systems.
To create a third-party shortcut, use the
files.create
method
of the API and make sure you set the MIME type
application/vnd.google-apps.drive-sdk
. Do not upload any content when
creating the file.
Java
File fileMetadata = new File();
fileMetadata.setName("Project plan");
fileMetadata.setMimeType("application/vnd.google-apps.drive-sdk");
File file = driveService.files().create(fileMetadata)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());
Python
file_metadata = {
'name': 'Project plan',
'mimeType': 'application/vnd.google-apps.drive-sdk'
}
file = drive_service.files().create(body=file_metadata,
fields='id').execute()
print 'File ID: %s' % file.get('id')
PHP
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'Project plan',
'mimeType' => 'application/vnd.google-apps.drive-sdk'));
$file = $driveService->files->create($fileMetadata, array(
'fields' => 'id'));
printf("File ID: %s\n", $file->id);
.NET
var fileMetadata = new File()
{
Name = "Project plan",
MimeType = "application/vnd.google-apps.drive-sdk"
};
var request = driveService.Files.Create(fileMetadata);
request.Fields = "id";
var file = request.Execute();
Console.WriteLine("File ID: " + file.Id);
Ruby
file_metadata = {
name: 'Project plan',
mime_type: 'application/vnd.google-apps.drive-sdk'
}
file = drive_service.create_file(file_metadata, fields: 'id')
puts "File Id: #{file.id}"
Node.js
var fileMetadata = {
'name': 'Project plan',
'mimeType': 'application/vnd.google-apps.drive-sdk'
};
drive.files.create({
resource: fileMetadata,
fields: 'id'
}, function (err, file) {
if (err) {
// Handle error
console.error(err);
} else {
console.log('File Id: ', file.id);
}
});
Objective-C
GTLRDrive_File *metadata = [GTLRDrive_File object];
metadata.name = @"Project plan";
metadata.mimeType = @"application/vnd.google-apps.drive-sdk";
GTLRDriveQuery_FilesCreate *query = [GTLRDriveQuery_FilesCreate queryWithObject:metadata
uploadParameters:nil];
query.fields = @"id";
[driveService executeQuery:query completionHandler:^(GTLRServiceTicket *ticket,
GTLRDrive_File *file,
NSError *error) {
if (error == nil) {
NSLog(@"File ID %@", file.identifier);
} else {
NSLog(@"An error occurred: %@", error);
}
}];
Adding custom thumbnails and indexable text
To increase the discoverability of files associated with third-party shortcuts, you can upload both thumbnail images and indexable text when inserting or modifying the file metadata. For more information, see Manage File Metadata.