I am trying to force download files in Firefox. I want to set content-disposition to "attachment" in the meta-data of the object. I have tried several things. But Metadata is not getting added. I have tried setting content-disposition like below.
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName,
s3key);
ResponseHeaderOverrides responseHeaderOverrides = new ResponseHeaderOverrides();
responseHeaderOverrides.setContentDisposition("attachment; filename =\"" + filename + "\"");
generatePresignedUrlRequest.setResponseHeaders(responseHeaderOverrides);
But in the console I still don't see the content-disposition getting added.
Please let me know if I missed something.
Thank You!
@debabratapatra content-disposition
is a response header, it won't show in the object's metadata in the S3 console after you uploaded the object.
If you are using the header with get presigned urls, your sample code should work fine if you just add the missing request method:
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, s3key)
.withMethod(HttpMethod.GET);
ResponseHeaderOverrides responseHeaderOverrides = new ResponseHeaderOverrides();
responseHeaderOverrides.setContentDisposition("attachment; filename =\"" + filename + "\"");
generatePresignedUrlRequest.setResponseHeaders(responseHeaderOverrides);
response-requested
Waiting on additional info or feedback. Will move to "closing-soon" in 5 days.
and removed
needs-triage
This issue or PR still needs to be triaged.
labels
Feb 27, 2021
@debora-ito Thanks for your response. I want to add content-disposition
to the metadata of the Object. Firefox doesn't automatically download .mov
files unless content-disposition=attachment
set in the metadata. Is there a way to add? Please let me know.
Thank you!
response-requested
Waiting on additional info or feedback. Will move to "closing-soon" in 5 days.
label
Mar 1, 2021
The sample code in my previous comment generates a presigned URL that seems to work on Firefox:
Can you specify what is not working in your case?
response-requested
Waiting on additional info or feedback. Will move to "closing-soon" in 5 days.
label
Mar 3, 2021
COMMENT VISIBILITY WARNING
Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
@debora-ito Thank you for the help. I want to ask if it's possible to pass content-disposition in parameters ? if it's the case i would like to know if i did it correctly.
public URL streamPresignedUrl( Disposition disposition)
ResponseHeaderOverrides responseHeaderOverrides = new ResponseHeaderOverrides();
responseHeaderOverrides.setContentDisposition( disposition.toString());
GeneratePresignedUrlRequest streamGeneratePresignedUrlRequest = new GeneratePresignedUrlRequest( getBucketName(), file)
.withMethod( HttpMethod.GET).withExpiration( expInstant);
streamGeneratePresignedUrlRequest.setResponseHeaders( responseHeaderOverrides);