可以在网络浏览器中打开.pdf文件而不是下载吗



截至目前,im使用签名url技术从GCS 获取文件

BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of(bucketName, gcsFolderPrefix + fullFileName)).build();
URL url = storage.signUrl(blobInfo, 15, TimeUnit.MINUTES,Storage.SignUrlOption.withV4Signature());

在浏览器中点击生成的签名url后,它被下载了,但我需要打开文件,我尝试添加响应标头,如下所示:

response.addHeader(HttpHeaders.CONTENT_TYPE, "multipart/form-data");
response.addHeader(HttpHeaders.CONTENT_DISPOSITION,"inline;filename=" + fileId.toString()+".pdf");

在生成SignedUrl 之前,您需要在GCS中更新blob的元数据

BlobInfo blobinfo = BlobInfo.newBuilder(BlobId.of(bucketName, gcsFolderPrefix + fullFileName))
//Add the correct content type
.setContentType("application/pdf")
.build();
// Update the Blob
storage.update(blobinfo);
URL url = storage.signUrl(blobInfo, 15, TimeUnit.MINUTES,Storage.SignUrlOption.withV4Signature());

最新更新