0

我试图进行可恢复的上传,但没有取得多大成功。

我阅读了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
}
4

1 回答 1

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

请注意 URL 中的上传。棘手!

于 2012-08-29T10:32:44.940 回答