使用Google Cloud Storage恢复上传会话uri请求

时间:2017-11-07 15:08:24

标签: upload google-cloud-storage resumable

我正在尝试使用Google云端存储JSON API生成可恢复的会话uri。在docs之后我将以下curl命令放在一起以仅满足所需的参数

curl \
-X POST \
-H "Content-Length: 1000000" \
-d "uploadType=resumable&name=cat.jpg" \
https://www.googleapis.com/upload/storage/v1/b/my-bucket/o

然而,这次超时并且服务器永远不会响应。请注意,仅在发送文件元数据时才需要Content-Type。我还尝试过添加元数据和相关数据,但这也失败了。

在文档中的示例请求中,有一个Authorization: Bearer [YOUR_AUTH_TOKEN]标题,在步骤中没有提到。我也尝试使用app的api键添加它,但这也会超时。

存储桶上的ACL已设置为所有可写用户。 CORS未配置。

有人能指出我出错的地方吗?

curl详细输出

* Hostname was NOT found in DNS cache
*   Trying 216.58.208.138...
* Connected to www.googleapis.com (216.58.208.138) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-ECDSA-AES128-GCM-SHA256
* Server certificate:
*    subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.googleapis.com
*    start date: 2017-10-24 08:38:00 GMT
*    expire date: 2017-12-29 00:00:00 GMT
*    subjectAltName: www.googleapis.com matched
*    issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*    SSL certificate verify ok.
> POST /upload/storage/v1/b/aits-resumables-test/o HTTP/1.1
> User-Agent: curl/7.35.0
> Host: www.googleapis.com
> Accept: */*
> Content-Length: 1000000
> Content-Type: application/json; charset=UTF-8
> 
* upload completely sent off: 33 out of 33 bytes

1 个答案:

答案 0 :(得分:1)

所以我现在有这个工作。我在JSON正文中添加了对象名称,然后直接将uploadType=resumable添加到url中,使其看起来如下所示

curl \
-X POST \
-H "Content-Type: application/json; charset=UTF-8" \
-H "X-Upload-Content-Type: image/jpeg" \
-H "X-Upload-Content-Length: 2000000" \
-d '{"name": "cat.jpg"}' \
https://www.googleapis.com/upload/storage/v1/b/my-bucket/o?uploadType=resumable