Does anyone here know how to create a pre-signed U...
# cfml-general
j
Does anyone here know how to create a pre-signed URL that will force a download vs display inline?
response-content-type=application/octet-stream"
is part of the equation, but I am struggling to make that work with aws-cfml
b
If I read your question correctly... You need a combination of cfheader and cfcontent to force the file to download... This shows the options for both 'inline' and 'attachment'... https://stackoverflow.com/questions/71774517/coldfusion-cfcontent-want-to-offer-open-file-but-not-download
j
Sorry, this is regarding pulling a file from S3 with a pre-signed URL. It is supposed to accept headers in the request that override the content type, but it's not working for me. https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html
b
The behavior depends on the browser and the file in question, really
In my experience octet-stream will always tell the browser to just download the file
Usually it's the other way around where you want the content type to be pdf or whatever for the browser to display it
j
yes, these headers are supposed to do that. it's just displaying the contents now
it doesn't look like they are getting translated correctly on the S3 side.
b
What is the file type in question?
j
an xml file
b
is there a header set in S3 when the file is stored?
Often times the issue is when saving the file, not retreiving it
The s3sdk has a setting to automatically guessing the mime type based on extension
Tho I forget if it's on or off by default
j
I used fileCopy and lucee virtual file system, but these headers are supposed to override whatever is in S3 per the docs
b
So long as the file is stored correctly to start, the download should "just work"
Ugh, yeah 97% chance Lucee screws it up
I doubt Lucee has any logic for that
That's why use the s3sdk for this stuff
It takes care of those things
You can set the headers, but prolly not with Lucee's abstracted file system functions, you'd need a proper s3 lib
I'm looking at the s3sdk's
getAuthenticatedURL()
to try and figure out how/where you'd pass the
response-content-type
bit
You wouldn't want to add it to the actual signing request-- maybe it would get tacked on to the
uri
? 🤔
I think the S3sdk will need updated to allow you to pass a
response-content-type
when signing a URL.
👍🏼 1
Just for completeness, here is the full list of headers that can be sent when signing a URL
Copy code
response-content-type
response-content-language
response-expires
response-cache-control
response-content-disposition
response-content-encoding
I have added support for this in the
s3sdk
module and am publishing it now. You can set a custom content type response header like so
Copy code
var presignedURL = s3.getAuthenticatedURL(
						bucketName      = testBucket,
						uri             = "example.txt",
						responseHeaders = { "content-type" : "text/plain" }
					);
or let the SDK choose the correct header based on the extension
Copy code
var presignedURL = s3.getAuthenticatedURL(
						bucketName      = testBucket,
						uri             = "example.txt",
						responseHeaders = { "content-type" : "auto" }
					);
Now published in version
5.6.0
🎉 1
j
Thanks, Brad!