Google Drive SDK

Work with Folders

Much of the information you'll need to get started inserting and retrieving files and folders is detailed in the Files reference. Here are a few more important keys to working with the Drive API methods for folders:

  • A folder is a file with the MIME type application/vnd.google-apps.folder and with no extension.
  • Folders are identified by the parents key in the state parameter.
  • You can use the alias root to refer to the root folder anywhere a file ID is provided

The rest of this page provides some details on important considerations for creating folders and inserting files in folders.

Creating a folder

In the Drive API, a folder is essentially a file — one identified by the special folder MIME type application/vnd.google-apps.folder. You can create a new folder by inserting a file with this MIME type and a folder title. Do not include an extension when setting a folder title.

To create a subfolder to a particular folder, specify the the correct ID in the parents property of the file. For example, to create the folder "pets" in an "images" folder whose id value is 0ADK06pfg:

POST https://www.googleapis.com/drive/v2/files
Authorization: Bearer {ACCESS_TOKEN}
Content-Type: application/json
...
{
  "title": "pets",
  "parents": [{"id":"0ADK06pfg"}]
  "mimeType": "application/vnd.google-apps.folder"
}

Inserting a file in a folder

Google Drive identifies the user's selected folder with the parents key in the state parameter. When users create a file in the top-level folder or a subfolder, the Drive UI passes this parameter and ID in the URL. When they open a file with the Drive UI, parent IDs are provided in the file metadata.

To insert a file in a particular folder, specify the correct ID in the parents property of the file, as shown:

POST https://www.googleapis.com/drive/v2/files
Authorization: Bearer {ACCESS_TOKEN}
Content-Type: application/json
...
{
  "title" : "cat.jpg",
  "mimeType" : "image/jpeg",
  "parents": [{
    "kind": "drive#fileLink",
    "id": "0Bz0bd074"
  }]
}

For more information, including client library examples for inserting files, see files.insert.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.