1

我的 javascript 应用程序创建一个文件,然后上传媒体内容。在 Chrome 中,一切都是 hunky dorey。在 Firefox 中,上传媒体的行为以某种方式破坏了 Drive 在文件和我的应用程序之间保持的关联,因此该图标不再是我的应用程序图标(它是默认的 Google 蓝色框),并且单击打开文件会出现错误页面.

所以步骤是...

  1. 创建文件(POST 到 /files)
  2. 在 Drive 中观察该文件是否存在并与我的应用程序图标一起显示
  3. 上传文件内容(PUT,uploadType=media 和 convert=false)
  4. 在 Drive 中观察文件的图标现在是 Google blue

如果我在 Chrome 中执行完全相同的操作,则在第 4 步,该文件仍与我的应用程序相关联并显示我的应用程序图标。

这是来自 Chrome 的媒体 PUT(即工作中的)

PUT https://content.googleapis.com/upload/drive/v2/files/0B6B-RNrxsCu2SERMMEFXMkdiOWM?uploadType=media&convert=false&useContentAsIndexableText=true&key=AIzaSyCt2bxTnrxo_IGvSUCBBAN_-29HJnzX_MU HTTP/1.1
:host: content.googleapis.com
x-origin: http://foo.myapp.appspot.com
x-javascript-user-agent: google-api-javascript-client/1.1.0-beta
x-goog-encode-response-if-executable: base64
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
accept-language: en-US,en;q=0.8,en-AU;q=0.6
authorization: Bearer ya29.AHES6ZQq1wAGltlEsnGKr6Dgtgkvp4zHCJsNTrXohnqrRmm3Ji8Yb14
x-referer: http://foo.myapp.appspot.com
x-clientdetails: appVersion=5.0%20(X11%3B%20Linux%20x86_64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F28.0.1500.95%20Safari%2F537.36&platform=Linux%20x86_64&userAgent=Mozilla%2F5.0%20(X11%3B%20Linux%20x86_64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F28.0.1500.95%20Safari%2F537.36
referer: https://content.googleapis.com/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.l49lMhuyXyk.O%2Fm%3D__features__%2Fam%3DEQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAItRSTOvD2NxxPLz0HiGHMXTek7IhOVTHg
content-length: 9

:version: HTTP/1.1
origin: https://content.googleapis.com
accept-encoding: gzip,deflate,sdch
:path: /upload/drive/v2/files/0B6B-RNrxsCu2SERMMEFXMkdiOWM?uploadType=media&convert=false&useContentAsIndexableText=true&key=AIzaSyCt1bxTnrxo_IGvSUCBBAN_-29HJnzX_MU
content-type: text/html
accept: */*
:scheme: https
:method: PUT

Query String 
uploadType=media
&convert=false
&useContentAsIndexableText=true
&key=AIzaSyCt2bxTnrxo_IGvSUCBBAN_-29HJnzX_MU

这是来自 Firefox 的媒体 PUT(即破坏文件关联的媒体)

火狐

PUT /upload/drive/v2/files/0B6B-RNrxsCu2UFZxbjExd0dGeTQ?uploadType=media&convert=false&useContentAsIndexableText=true&key=AIzaSyCt2bxTnrxo_IGvSUCBBAN_-29HJnzX_MU HTTP/1.1
Host: content.googleapis.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: text/html; charset=UTF-8
Authorization: Bearer ya29.AHES6ZQrG_PQOmEZD4cBwgrjiNKNZUBc2RzAnOTmZwTJReX664MWvu8
X-ClientDetails: appVersion=5.0%20(X11)&platform=Linux%20x86_64&userAgent=Mozilla%2F5.0%20(X11%3B%20Linux%20x86_64%3B%20rv%3A21.0)%20Gecko%2F20100101%20Firefox%2F21.0
X-JavaScript-User-Agent: google-api-javascript-client/1.1.0-beta
X-Origin: http://foo.myapp.appspot.com
X-Referer: http://foo.myapp.appspot.com
X-Goog-Encode-Response-If-Executable: base64
Referer: https://content.googleapis.com/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.l49lMhuyXyk.O%2Fm%3D__features__%2Fam%3DEQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAItRSTOvD2NxxPLz0HiGHMXTek7IhOVTHg
Content-Length: 12
Connection: keep-alive

convert false
key AIzaSyCt2bxTnrxo_IGvSUCBBAN_-29HJnzX_MU
uploadType  media
useContentAsIndexableText   true

回复如下。返回 Item json 之间的唯一区别是 Chrome 版本具有 mimetype "text/html" 而 Firefox 具有 mimetype "text/html; charset=UTF-8"

火狐响应

   Content-Length 2986
    Content-Type application/json
    Date Sat, 24 Aug 2013 10:44:37 GMT
    Etag "NaUPR8AuDOKgpQqXUqmAHnRC-Nk/R_dzQ2tl2e997lu1SqOGTX63YoE"
    Server HTTP Upload Server Built on Aug 7 2013 16:51:13 (1375919473)
    X-Firefox-Spdy 3


"kind":"drive#file",
"id":"0B6B-RNrxsCu2cjlldTNoV01JVHc",
"etag":"\"NaUPR8AuDOKgpQqXUqmAHnRC-Nk/NM5C-3sulAfFZA1V-IIsA-E9_AA\"",
"selfLink":"https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2cjlldTNoV01JVHc",
"webContentLink":"https://docs.google.com/uc?id=0B6B-RNrxsCu2cjlldTNoV01JVHc&export=download",
"alternateLink":"https://docs.google.com/file/d/0B6B-RNrxsCu2cjlldTNoV01JVHc/edit?usp=drivesdk",
"iconLink":"https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png",
"thumbnailLink":"https://lh3.googleusercontent.com/1KctCx9tjxe6vSn7piLUzfYQuNKQVzMUd6Phn8dTdlHKfQlQsXi77PyOOLkwS-0q3g=s220",
"title":"burcu",
"mimeType":"text/html; charset=UTF-8",
"labels":{
    "starred":false,
    "hidden":false,
    "trashed":false,
    "restricted":false,
    "viewed":true
},
"createdDate":"2013-08-24T10:44:12.851Z",
"modifiedDate":"2013-08-24T10:44:36.440Z",
"modifiedByMeDate":"2013-08-24T10:44:36.440Z",
"lastViewedByMeDate":"2013-08-24T10:44:36.440Z",
"parents":[
    {
        "kind":"drive#parentReference",
        "id":"0B6B-RNrxsCu2RVVQZ1NFWGZYUW8",
        "selfLink":"https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2cjlldTNoV01JVHc/parents/0B6B-RNrxsCu2RVVQZ1NFWGZYUW8",
        "parentLink":"https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2RVVQZ1NFWGZYUW8",
        "isRoot":false
    },
    {
        "kind":"drive#parentReference",
        "id":"0B6B-RNrxsCu2MFZ0dEx6a2xEQU0",
        "selfLink":"https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2cjlldTNoV01JVHc/parents/0B6B-RNrxsCu2MFZ0dEx6a2xEQU0",
        "parentLink":"https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2MFZ0dEx6a2xEQU0",
        "isRoot":false
    }
],
"downloadUrl":"https://doc-0k-54-docs.googleusercontent.com/docs/securesc/i6kcvi4n5dug3hk78lqkpogagkdpecs6/krhjojomqafnrdg6943a1fhtnfjg4b8v/1377338400000/15125351317662028975/15125351317662028975/0B6B-RNrxsCu2cjlldTNoV01JVHc?h=16653014193614665626&e=download&gd=true",
"userPermission":{
    "kind":"drive#permission",
    "etag":"\"NaUPR8AuDOKgpQqXUqmAHnRC-Nk/ajH3QRzRTY6aEeYY5k2JAipDckI\"",
    "id":"me",
    "selfLink":"https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2cjlldTNoV01JVHc/permissions/me",
    "role":"owner",
    "type":"user"
},
"originalFilename":"burcu",
"fileExtension":"",
"md5Checksum":"47088846bea0768b700fa76afc1e2aee",
"fileSize":"6",
"quotaBytesUsed":"6",
"ownerNames":[
    " Demo"
],
"owners":[
    {
        "kind":"drive#user",
        "displayName":" Demo",
        "isAuthenticatedUser":true,
        "permissionId":"15125351317662028975"
    }
],
"lastModifyingUserName":" Demo",
"lastModifyingUser":{
    "kind":"drive#user",
    "displayName":" Demo",
    "isAuthenticatedUser":true,
    "permissionId":"15125351317662028975"
},
"editable":true,
"copyable":true,
"writersCanShare":true,
"shared":false,
"appDataContents":false,
"headRevisionId":"0B6B-RNrxsCu2MWN5clphQUlBNStwM1FLTWZWS3R0RkViVkh3PQ"

}

铬反应

content-length:
2977
content-type:
application/json
date:
Sat, 24 Aug 2013 10:48:29 GMT
etag:
"NaUPR8AuDOKgpQqXUqmAHnRC-Nk/pESqU9sAUSQgLet1Hkz2wJT0Nyw"
server:
HTTP Upload Server Built on Aug 7 2013 16:51:13 (1375919473)
status:
200 OK
version:
HTTP/1.1


{
"kind": "drive#file",
"id": "0B6B-RNrxsCu2cjlldTNoV01JVHc",
"etag": "\"NaUPR8AuDOKgpQqXUqmAHnRC-Nk/7kdHmkAGWmpQ_v_pNZFbF-GLMic\"",
"selfLink": "https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2cjlldTNoV01JVHc",
"webContentLink": "https://docs.google.com/uc?id=0B6B-RNrxsCu2cjlldTNoV01JVHc&export=download",
"alternateLink": "https://docs.google.com/file/d/0B6B-RNrxsCu2cjlldTNoV01JVHc/edit?usp=drivesdk",
"iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png",
"thumbnailLink": "https://lh4.googleusercontent.com/AXTF6nVY78BZi00eTaAEwmdTfeXVC5Ny3zYEIVEPOTwPNGqy7LC9dKiqzZBg9-q3LA=s220",
"title": "burcu",
"mimeType": "text/html",
"labels": {
"starred": false,
"hidden": false,
"trashed": false,
"restricted": false,
"viewed": true
},
"createdDate": "2013-08-24T10:44:12.851Z",
"modifiedDate": "2013-08-24T10:48:27.913Z",
"modifiedByMeDate": "2013-08-24T10:48:27.913Z",
"lastViewedByMeDate": "2013-08-24T10:48:27.913Z",
"parents": [
{
"kind": "drive#parentReference",
"id": "0B6B-RNrxsCu2RVVQZ1NFWGZYUW8",
"selfLink": "https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2cjlldTNoV01JVHc/parents/0B6B-RNrxsCu2RVVQZ1NFWGZYUW8",
"parentLink": "https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2RVVQZ1NFWGZYUW8",
"isRoot": false
},
{
"kind": "drive#parentReference",
"id": "0B6B-RNrxsCu2MFZ0dEx6a2xEQU0",
"selfLink": "https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2cjlldTNoV01JVHc/parents/0B6B-RNrxsCu2MFZ0dEx6a2xEQU0",
"parentLink": "https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2MFZ0dEx6a2xEQU0",
"isRoot": false
}
],
"downloadUrl": "https://doc-0k-54-docs.googleusercontent.com/docs/securesc/i6kcvi4n5dug3hk78lqkpogagkdpecs6/krhjojomqafnrdg6943a1fhtnfjg4b8v/1377338400000/15125351317662028975/15125351317662028975/0B6B-RNrxsCu2cjlldTNoV01JVHc?h=16653014193614665626&e=download&gd=true",
"userPermission": {
"kind": "drive#permission",
"etag": "\"NaUPR8AuDOKgpQqXUqmAHnRC-Nk/ajH3QRzRTY6aEeYY5k2JAipDckI\"",
"id": "me",
"selfLink": "https://content.googleapis.com/drive/v2/files/0B6B-RNrxsCu2cjlldTNoV01JVHc/permissions/me",
"role": "owner",
"type": "user"
},
"originalFilename": "burcu",
"fileExtension": "",
"md5Checksum": "423f5e2804f551616956ca8cb4a684b0",
"fileSize": "9527",
"quotaBytesUsed": "9527",
"ownerNames": [
" Demo"
],
"owners": [
{
"kind": "drive#user",
"displayName": " Demo",
"isAuthenticatedUser": true,
"permissionId": "15125351317662028975"
}
],
"lastModifyingUserName": " Demo",
"lastModifyingUser": {
"kind": "drive#user",
"displayName": " Demo",
"isAuthenticatedUser": true,
"permissionId": "15125351317662028975"
},
"editable": true,
"copyable": true,
"writersCanShare": true,
"shared": false,
"appDataContents": false,
"headRevisionId": "0B6B-RNrxsCu2Zmg1M0todDBPcERUREtmTjZuQjlCQjJIOUVJPQ"
}
4

1 回答 1

1

我会说这是一个错误来回答我自己的问题。

总而言之,使用带有 Firefox 的 GAPI Javascript 客户端更新内容会导致 Drive 中的 mime-type 包含字符集(例如“text/html; charset=UTF-8”)。因为这与 API 控制台中声明的 mime 类型(“text/html”)不匹配,所以 Drive web 应用程序不会将该文件与我的应用程序相关联。

该错误可被视为位于以下三个位置之一:-

  1. 将内容类型标头设置为“text/html; charset=UTF-8”可能是 GAPI JS 客户端错误。
  2. 这可能是一个 Drive SDK 错误,文件 mime 类型应该始终是我在创建文件时明确声明的类型,并且应该忽略任何媒体上传的 mime 类型标头。或者可以认为 Drive SDK 在使用它来设置文件的 mime 类型之前,应该从 content-type 标头中去除字符集。
  3. 它可能是 Drive webapp 错误,它应该将“text/html”和“text/html; charset=UTF-8”视为相同的 mime 类型。
于 2013-08-24T16:32:39.507 回答