Skip to content

Add Canonicalized_Extension_Headers for signedURL builder #2000

Description

@salrashid123

Cloud Storage SignedURLs allows for custom headers you can set to define metadata:

It doesn't look like you can add this in now during signURL construction:

note BlobInfo has metadata defined in it already so maybe use that:

the following shows how to manually construct the signed URL with canonical headers outside of this library

ServiceAccountCredentials creds = ServiceAccountCredentials.fromStream(new FileInputStream("YOUR_CERT.json")); 

String BUCKET_NAME = "your_bucket"; 
String OBJECT_NAME = "a.txt"; 
String SERVICE_ACCOUNT_EMAIL = "svc-2-429@your_project.iam.gserviceaccount.com"; 
String verb = "PUT"; 
long expiration = System.currentTimeMillis()/1000 + 60; 
String Canonicalized_Extension_Headers = "x-goog-meta-icecreamflavor:vanilla"; 


byte[] sr = creds.sign( (verb + "\n\n\n" + expiration + "\n" + Canonicalized_Extension_Headers + 
"\n" + "/" + BUCKET_NAME + "/" + OBJECT_NAME ).getBytes() ); 
String url_signature = new String(Base64.encodeBase64( sr )); 
String signed_url = "https://storage.googleapis.com/" + BUCKET_NAME + "/" + OBJECT_NAME + 
"?GoogleAccessId=" + SERVICE_ACCOUNT_EMAIL + 
"&Expires=" + expiration + 
"&Signature=" + URLEncoder.encode(url_signature, "UTF-8"); 

System.out.println(signed_url); 

Just to note, you'll need to post the headers too but thats outside of this FR:

curl -v -H "x-goog-meta-icecreamflavor:vanilla" -X PUT "https://storage.googleapis.com/.....&Signature=Ol1zLbXd0W%2B3q....3D%3D" --upload-file a.txt 

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Sponsor
    SponsoredKunjungi sekarang
    Promo