0

我使用谷歌云存储 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();

没关系。但我不能使用版本号。

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

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

1 回答 1

0

请记住,正如这里提到的,签名的 URL 只能通过 XML API 端点访问 Cloud Storage 中的资源。

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

于 2021-01-15T11:18:19.953 回答