微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Google Cloud Storage - 从带有代号的签名网址获取下载链接

如何解决Google Cloud Storage - 从带有代号的签名网址获取下载链接

我使用 Google Cloud Storage API。我像这样创建签名网址;

 var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer("username@iam.gserviceaccount.com").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();

没关系。但我不能为版本使用第 1 代。

这是没有签名网址的正常下载; 我在签名网址上寻找“IfGenerationMatch =”

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

解决方法

请注意,正如前面提到的 here,签名网址只能通过 XML API 端点访问 Cloud Storage 中的资源。

IfGenerationMatch 前提条件仅出现在 JSON API 中,因此您不会使用签名 URL 找到它。您需要使用 x-goog-if-generation-match 前置条件,因为它与 XML API 中的等价。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。