I've done a lot of research, and lots of tests before asking this question, as usual, I don't like asking just because.
I can't make a signed url using java that displays the file (content-disposition:inline) in the browser.
When I do it using the PHP sdk, I have no trouble, I copy and paste the signed url in the browser and the file is displayed in the browser. But when using java for the same file, the file is downloaded.
In this post, it mentions something about clear metadata and appending "&response-content-disposition=inline", to the signed url, it is also mentioned in the google cloud docs.
I have tried in several ways, but I just can't make it work, when I append the "&response-content-disposition=inline" as specified in the docs, I get the following error:
<Code>SignatureDoesNotMatch</Code>
<Message> The request signature we
calculated does not match the signature you provided. Check your
Google secret key and signing method. </Message>
But it says that those parameters aren't included in the calculation of the signing, so I don't know what's happening.
In code I've tried:
(transformed to kotlin)
val blobInfo = BlobInfo.newBuilder(BlobId.of(configuracion.bucket, fileName)).build()
val newMetadata: MutableMap<String, String> = HashMap()
newMetadata["contentDisposition"] = "inline"
blobInfo.toBuilder().setMetadata(newMetadata).build()
val signUrl = storage.signUrl(blobInfo, expiration, TimeUnit.MILLISECONDS,Storage.SignUrlOption.withV4Signature())
return signUrl.toString()
But no luck.
I would think that there should be a pretty straight forward way to set content-disposition to whatever I want, but it doesn't seem to be the case.
The way I generate the signed url is simple:
val storage = this.getStorageDefaultInstance()
val blobInfo = BlobInfo.newBuilder(BlobId.of(configuracion.bucket, fileName)).build()
val signUrl = storage.signUrl(blobInfo, expiration, TimeUnit.MILLISECONDS, Storage.SignUrlOption.withV4Signature())
return signUrl.toString()
Any suggestions?
EDIT
I noticed that when I request the file using PHP SDK I get the reponse header "content-type: application/pdf", while on Java I get "content-type: application/octet-stream", maybe this is what I need to change.
I tried overwriting metada using:
val newMetadata: MutableMap<String, String> = HashMap()
newMetadata["contentDisposition"] = "inline"
newMetadata["contentType"] = "application%2Fpdf"
val blobInfo = BlobInfo.newBuilder(BlobId.of(configuracion.bucket, fileName)).setMetadata(newMetadata).build()
Still, no luck.