Create a shortcut to an external file

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/ Do not upload any content when creating the file.


File fileMetadata = new File();
fileMetadata.setName("Project plan");

File file = driveService.files().create(fileMetadata)
System.out.println("File ID: " + file.getId());


from __future__ import print_function

import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

def create_shortcut():
    """Create a third party shortcut

    Load pre-authorized user credentials from the environment.
    TODO(developer) - See
    for guides on implementing OAuth2 for the application.
    creds, _ = google.auth.default()

        # create gmail api client
        service = build('drive', 'v3', credentials=creds)
        file_metadata = {
            'title': 'Project plan',
            'mimeType': 'application/'

        # pylint: disable=maybe-no-member
        file = service.files().create(body=file_metadata,
        print(F'File ID: {file.get("id")}')

    except HttpError as error:
        print(F'An error occurred: {error}')
    return file.get('id')

if __name__ == '__main__':


$fileMetadata = new Google_Service_Drive_DriveFile(array(
    'name' => 'Project plan',
    'mimeType' => 'application/'));
$file = $driveService->files->create($fileMetadata, array(
    'fields' => 'id'));
printf("File ID: %s\n", $file->id);


using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Services;

namespace DriveV3Snippets
    // Class to demonstrate Drive's create shortcut use-case
    public class CreateShortcut
        /// <summary>
        /// Create a third party shortcut.
        /// </summary>
        /// <returns>newly created shortcut file id, null otherwise.</returns>
        public static string DriveCreateShortcut()
                /* Load pre-authorized user credentials from the environment.
                 TODO(developer) - See for 
                 guides on implementing OAuth2 for your application. */
                GoogleCredential credential = GoogleCredential

                // Create Drive API service.
                var service = new DriveService(new BaseClientService.Initializer
                    HttpClientInitializer = credential,
                    ApplicationName = "Drive API Snippets"

                // Create Shortcut for file.
                var fileMetadata = new Google.Apis.Drive.v3.Data.File()
                    Name = "Project plan",
                    MimeType = "application/"
                var request = service.Files.Create(fileMetadata);
                request.Fields = "id";
                var file = request.Execute();
                // Prints the shortcut file id.
                Console.WriteLine("File ID: " + file.Id);
                return file.Id;
            catch (Exception e)
                // TODO(developer) - handle error appropriately
                if (e is AggregateException)
                    Console.WriteLine("Credential Not found");
            return null;


file_metadata = {
    name: 'Project plan',
    mime_type: 'application/'
file = drive_service.create_file(file_metadata, fields: 'id')
puts "File Id: #{}"


 * Create a third party shortcut
 * @return{obj} shortcut Id
 * */
async function createShortcut() {
  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app

  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({scopes: ''});
  const service ={version: 'v3', auth});
  const fileMetadata = {
    'title': 'Project plan',
    'mimeType': 'application/',

  try {
    const file = await service.files.create({
      resource: fileMetadata,
      fields: 'id',
    console.log('File Id:',;
  } catch (err) {
    // TODO(developer) - Handle error
    throw err;


GTLRDrive_File *metadata = [GTLRDrive_File object]; = @"Project plan";
metadata.mimeType = @"application/";
GTLRDriveQuery_FilesCreate *query = [GTLRDriveQuery_FilesCreate queryWithObject:metadata
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.