// This method is used to return the signed URL , After getting the URL I can able to view the //preview of the file which is in GCS, But in my case signed URL is not working its throwing the below //Exception while accessing in the browser. How to resolve this issue?
BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of(bucketName, gcsFolderPrefix + fullFileName)).build();
URL url = storage.signUrl(blobInfo, 15, TimeUnit.MINUTES, Storage.SignUrlOption.withV4Signature());
return url;
//Exception
//此xml文件似乎没有任何与之关联的样式信息。文档树如下所示。
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Details>No such object: google storage location</Details>
</Error>
2条答案
按热度按时间mwecs4sa1#
错误表明您的文件不存在于gcs bucket中。
请仔细检查您试图检索的路径。
你能用电脑下载那个文件吗
gsutil
?eiee3dmh2#
如果您的文件是.pdf文件,则需要在生成signedurl之前更新google云存储中blob的元数据。
要预览.pdf文件,必须先下载该文件,然后才能看到它。
如果只想在浏览器中查看文件,则应向浏览器指示应在浏览器中查看该文件,因此http响应应包含以下标头:
通过在google云存储java api的blobinfo.builder类中搜索,我们可以在java中设置内容类型和内容配置如下:
要下载而不是查看文件: