我试图进行可恢复的上传但没有取得多大成功。
我阅读了https://developers.google.com/drive/manage-uploads#resumable页面,但我无法弄清楚如何在第一次请求的响应中获得此“位置”标题。
API文档指定我们可以在第一个URL上创建一个POST或PUT,但是如果我创建一个PUT,我会得到一个404,如果我发布一个POST,我会得到一个没有内容创建的新文件响应中没有位置标题。
这是我的POST查询(使用PUT和完全相同的查询返回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";
}
和回复:
"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
}
答案 0 :(得分:1)
文件插入文档页面(https://developers.google.com/drive/v2/reference/files/insert)中指定的HTTP请求如下:
POST https://www.googleapis.com/drive/v2/files
但这是错误的。 上传文件页面(https://developers.google.com/drive/manage-uploads#resumable)上指定了正确的方法,并且是:
POST https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable
请注意网址中的上传。棘手!