简体   繁体   中英

Google cloud storage : get upload link (JAVA)

I can create Bucket in my cloub but I can not find how to retrieve the url to send files in this bucket.

I can find my bucket with its name :

try {
            getBucket = storage.buckets().get("bucketName");
            Bucket bucket = getBucket.execute();
        System.out.println(bucket.getDefaultObjectAcl());
    } catch (IOException e) {
        e.printStackTrace();
    }

But getDefaultObjectAcl and getAcl send me null.

How to retrieve this url? Thx.

I found how to upload a file without Token.

https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#resumable

First you must use Token and file's info you want to upload to create the resumable upload link.

Send this to google.

POST /upload/storage/v1/b/myBucket/o?uploadType=resumable HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer your_auth_token
Content-Length: 38
Content-Type: application/json; charset=UTF-8
X-Upload-Content-Type: image/jpeg
X-Upload-Content-Length: 2000000
{
  "name": "myObject"
}

In the response header there is a link to use to upload a file to Google Cloud storage.

Location: https://example.storage.googleapis.com/music.mp3?upload_id=tvA0ExBntDa...gAAEnB2Uowrot

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