I tried to make a resumable upload without much success.
I read the https://developers.google.com/drive/manage-uploads#resumable page but I can’t figure out how to get this “Location” header in the response of the first request.
The API documentation specify that we can make either a POST or a PUT on the first URL, but if I make a PUT, I get a 404, and if I make a POST I get a new file created with no content and no Location header in the response.
Here is my POST query (with a PUT and exactly the same query it returns a 404):
POST https://www.googleapis.com/drive/v2/files?uploadType=resumable
Accept = application/json
Authorization = Bearer xxxxxxxxx
Content-Length = 71
Content-Type = application/json
X-Upload-Content-Length = 10
X-Upload-Content-Type = text/plain
{
mimeType = "text/plain";
parents = (
{
id = root;
}
);
title = "test.txt";
}
and the response:
"Cache-Control" = "no-cache, no-store, max-age=0, must-revalidate";
"Content-Type" = "application/json; charset=UTF-8";
Date = "Wed, 29 Aug 2012 09:53:15 GMT";
Etag = "\"UlXjrWs5BKksMni8RDMKhlFkHGQ/MTM0NjIzMzk5NTA2MQ\"";
Expires = "Fri, 01 Jan 1990 00:00:00 GMT";
Pragma = "no-cache";
Server = GSE;
"Transfer-Encoding" = Identity;
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = SAMEORIGIN;
"X-XSS-Protection" = "1; mode=block";
{
"kind": "drive#file",
"id": "xxxx",
"etag": "\"xxxx\"",
"selfLink": "https://xxxx",
"webContentLink": "https://xxxx",
"alternateLink": "https://xxxx",
"title": "test.txt",
"mimeType": "text/plain",
"labels": {
"starred": false,
"hidden": false,
"trashed": false,
"restricted": false,
"viewed": true
},
"createdDate": "2012-08-29T09:53:15.200Z",
"modifiedDate": "2012-08-29T09:53:15.061Z",
"modifiedByMeDate": "2012-08-29T09:53:15.061Z",
"lastViewedByMeDate": "2012-08-29T09:53:15.061Z",
"parents": [
{
"kind": "drive#parentReference",
"id": "xxxx",
"selfLink": "https://xxxx",
"parentLink": "https://xxxx",
"isRoot": true
}
],
"downloadUrl": "https://xxxx",
"userPermission": {
"kind": "drive#permission",
"etag": "\"xxxx\"",
"id": "me",
"selfLink": "https://xxxx",
"role": "owner",
"type": "user"
},
"originalFilename": "test.txt",
"fileExtension": "txt",
"md5Checksum": "xxxx",
"fileSize": "0",
"quotaBytesUsed": "0",
"ownerNames": [
"xxxx"
],
"lastModifyingUserName": "xxxx",
"editable": true,
"writersCanShare": true
}
The HTTP Request specified in the Files Insert documentation page ( https://developers.google.com/drive/v2/reference/files/insert) is the following :
But it’s wrong. The correct method is specified on the Upload Files page (https://developers.google.com/drive/manage-uploads#resumable) and is :
Note the upload in the URL. Tricky!