Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
593 views
in Technique[技术] by (71.8m points)

c# - Google Cloud Storage - Getting Download link from Signed Url with Generation No

I use Google Cloud Storage Apis. I create Signed Url like this;

 var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer("[email protected]").FromPrivateKey(PrivateKey));
        var urlSigner = UrlSigner.FromServiceAccountCredential(credential);
        string url = urlSigner.Sign(bucketName, "Sample.txt", TimeSpan.FromDays(7));

        var httpClient = new System.Net.Http.HttpClient();

        System.Net.Http.HttpResponseMessage response  = await httpClient.GetAsync(url);
        var content = await response.Content.ReadAsByteArrayAsync();

it's ok. But I can't use Generation No for versions.

This is normal download without signed url; I looking for "IfGenerationMatch = " on Signed Url

 await client.DownloadObjectAsync(
             bucket: bucketName,
             objectName: sourcePath,
             destination: destinationPath,
             progress: progress,
             options: new DownloadObjectOptions()
             { ChunkSize = 1048576, Range = rangeHeaderValue, IfGenerationMatch = data.GenerationNo }
         );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Keep in mind that as mentioned here, the signed URLs can only access resources in Cloud Storage through XML API endpoints.

The IfGenerationMatch precondition is only present in the JSON API, as such, you will not find it using the signed URLs. You would need to use the x-goog-if-generation-match precondition since that's the equivalent in the XML API.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...