简体   繁体   中英

Resumable upload session uri request with Google Cloud Storage

I am trying to generate a resumable session uri using the Google Cloud Storage JSON API. Following the docs I have put together the following curl command to satisfy only the required arguments

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

However, this times out and the server never responds. Note that Content-Type is only required if also sending the file metadata. I've tried also adding the metadata and associated data, but this also fails.

In the example request in the docs there is an Authorization: Bearer [YOUR_AUTH_TOKEN] header which isn't mentioned in the steps. I have also tried adding this, using the app's api key, but this also times out.

The ACL on the bucket has been set to all users writable. CORS is not configured.

Could anyone point out where I'm going wrong?

The curl verbose output is

* 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

So I have this working now. I added the object name in the JSON body and then added the uploadType=resumable to the url directly so that it looks like the following

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM