getSignedUrl arguments promptSaveAs and responseDisposition have no effect on the eventual content-disposition header.
bucket.file('/myvideo.mp4').getSignedUrl({
action: 'read',
// Note: I include both parameters here for demonstration understanding, as the documentation states,
// that promptSaveAs should have no effect when responseDisposition is supplied
promptSaveAs: 'myvideo.mp4',
responseDisposition: 'attachment; filename*=utf-8\'\'myvideo.mp4'
});
Ends up returning
inline; filename*=utf-8''myvideo.mp4
when the URI gets navigated to, no matter which combination of promptSaveAs and responseDisposition are supplied, or which values are supplied to those parameters.
OS: OSX
Node.js v8
NPM 5
@google-cloud/storage version: 1.7.0, used through firebase-admin (https://github.com/firebase/firebase-admin-node) v6.0.0
Steps to reproduce
getSignedUrl found on the File class, setting either a promptSaveAs or responseDisposition parameter.Hey @major-mann, sorry for the delay. I ran this, and it seems to work for me, but please let me know where I might have simplified my expectations:
file
.getSignedUrl({
action: 'read',
expires: new Date('2025'),
promptSaveAs: 'custom-file.jpg',
responseDisposition: 'attachment; filename*=utf-8\'\'custom-file.jpg',
})
.then(resp => console.log(resp[0])) // The URL I curl at later
.catch(console.error)
$ curl -I "{{ the returned URL }}"
HTTP/2 200
...
content-disposition: attachment; filename*=utf-8''custom-file.jpg
...
access-control-expose-headers: Content-Disposition
...
Visiting in Chrome will auto-download the file as custom-file.jpg (which is not the actual name of the object stored in GCS).
When I'm using arguments of
{
action: 'read',
expires: 1541190593336,
promptSaveAs: '<filename>',
responseDisposition: 'attachment; filename*=utf-8\'\'<filename>'
}
Gives me a URI in of the following form
https://storage.googleapis.com/<project id>.appspot.com/<encoded media path>?<Access information>
Which when curled (with -I) gives me.
HTTP/2 200
x-guploader-uploadid: <long identifier string>
expires: Thu, 01 Nov 2018 20:31:58 GMT
date: Thu, 01 Nov 2018 20:31:58 GMT
cache-control: private, max-age=0
last-modified: Wed, 05 Sep 2018 20:40:18 GMT
etag: "541923aa1e627c1fe46bef5c0f113df1"
x-goog-generation: 1536180018574176
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 152562361
x-goog-meta-firebasestoragedownloadtokens: <uuid>
content-type: video/mp4
content-disposition: inline; filename*=utf-8''<filename>
x-goog-hash: crc32c=p+FUqQ==
x-goog-hash: md5=VBkjqh5ifB/ka+9cDxE98Q==
x-goog-storage-class: STANDARD
accept-ranges: bytes
content-length: 152562361
server: UploadServer
alt-svc: quic=":443"; ma=2592000; v="44,43,39,35"
I see that there is the access-control-expose-headers header which I do not get. Is there some type of bucket configuration I might be missing?
I will try to test with the library directly this weekend and hopefully be able to pull additional information out.
For anyone else running into this issue it may be due to existing metadata on the file overriding the content-disposition header.
I used fileRef.setMetadata({contentDisposition: null}); then used an already generated URL and it works as expected now.
Hopefully it's the same for you @major-mann
Thanks for stopping by to help, @boxidau! Let us know if there is more our library can do @major-mann.
promptSaveAs automatically sets proper responseDisposition.
https://googleapis.dev/nodejs/storage/latest/File.html#getSignedUrl
Name | Type | Attributes | Default | Description
-- | -- | -- | -- | --
promptSaveAs | string | config.responseDisposition聽is set.
Most helpful comment
For anyone else running into this issue it may be due to existing metadata on the file overriding the content-disposition header.
I used
fileRef.setMetadata({contentDisposition: null});then used an already generated URL and it works as expected now.Hopefully it's the same for you @major-mann