I have a test.txt file stored in an S3 bucket and when i click on "Open", i want it to get downloaded but it is opening in the browser itself. I have tried setting Content-disposition to attachment but it did not work. Is there any way to force download text and json files from S3?
Thanks in advance.
When you click Open in the S3 console, it sends response-content-disposition=inline to S3 which overwrites whatever Content-Disposition set on the object to inline. Content-Disposition: inline indicates that the content of this file can be displayed inside the Web page. This is why setting Content-Disposition won't work in this case.
If you need to download the file (instead of opening it in the web page) from the S3 console, you can either
click Open
on the new popup page, right click and choose Save as ...
Or
click Download as in the S3 web console
Related
We have a client incorrectly setting the Content-Type to application/json when uploading a pdf file to s3. This results in the client library we use to download the file to give it the wrong extension, also happens when you download the file from the s3 console, even though it has .pdf as the suffix, it downloads to .json.
Is there anyway to prevent clients from doing this? The Content type should always be application/x-www-form-urlencoded from my understanding.
Our team is building a web app that allows users to download video files. We currently host our files on AWS S3, but since our site doesn't reside on AWS, we can't use <a href="blah"> to prompt download. If we use that html element, users simply get redirected to a video player - which is fine, but Safari on mobile doesn't allow for users to download the video file via the video player.
We found that manually setting the file's content disposition to attachment on S3 works, but we have not found a way to automate that. We tried adding a content-disposition: attachment key-value pairing in our payload, which works, but adds a "User defined" meta data in the form of x-amz-meta-content-disposition, which doesn't work as the file could not be downloaded as an attachment. It seems only "System defined" works.
Has anyone ever encountered this issue before and found a workaround?
see screenshot for what I'm referencing
You can set the content disposition when the file is created.
This is done by uploading the file via a presigned url.
See https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html for details on the presigned urls.
Alternatively you can use a presigned url to return to get the file from S3 and override the content disposition header on the GET request.
My question came out when I experienced two different behaviors in object URL from json files stored in a s3 bucket.
Consider a json file: mydata.json
If I upload this file using s3 dashboard from AWS website, I am able to see data in browser: //s3-us-west-2.amazonaws.com/bucket/folder/mydata.json. I am also able to read this data from a different application if I create a specific configuration in s3 bucket.
For the other hand, if I use boto3 library for python and upload the same file in the same bucket (making file public in the process), when I click object URL it downloads the file, but it doesn't open data in browser.
This is the code I used:
# upload json file
bucket.upload_file(path, jsonkey)
object_acl = s3.ObjectAcl('bucket_name', jsonkey)
bucket_response = object_acl.put(ACL='public-read')
I explored file properties such as metadata. When I upload file via dashboard, the metadata assigned is Content-Type: application/json, and via boto3 is Content-Type: binary/octet-stream. I don't really know if metadata affects the object URL behavior.
In this context, how can I properly configure files in json format to be downloaded or to be read? I mean, what is the main configuration that affects object URL behavior?
I couldn't find a significant difference between both methods (dashboard and boto3) in properties or permissions, besides Content-Type in metadata. However, when I tried to change Content-Type, behavior was the same.
Any other information I can provide to clarify this question, be free to ask. Thanks in advance.
The documentation for the S3 bucket resource's upload_file() method is not ideal as it simply refers you to the equivalent S3Transfer docs for how extra arguments can be used.
Try the following:
bucket.upload_file(path, jsonkey, ExtraArgs={'ContentType': "application/json"})
I have a set of images stored on S3 that should be displayed on the browser. These images have a content type of application/octet-stream and can be viewed in Chrome and Firefox.
My understanding is that Internet Explorer cannot view application/octet-stream content, or it is unable to realize that the S3 object is actually an image.
I've tried to upload new versions of my images onto S3 and manually adding a Metadata Header/Value pair of Content-Type and image/png (using the S3 console, not CLI). However, I still see the same application/octet-stream on IE.
Is it possible to configure my application (Angular4/SpringBoot/Tomcat) to tell IE to look at that type of content, or am I looking at the wrong place in S3?
From my backend, where I set my AWS S3 api I was setting the response headers to 'application/octet-stream'.
Currently when I place a property list file (plist extension) to a S3 bucket, it sets the Content-type to application/octet-stream for some reason. It causes issues when I download it in Objective-C (iOS).
How can change the bucket policy so it automatically sets the Content-type to text/plain
You cannot. The default content-type is "application/octet-stream".
Please find below the aws documentation for the same
http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
The only option you have is setting the content-type at the time of upload or updating it once the upload is complete.
You can change the Content-Type using the metadata properties of the file in S3 :
If you're on windows, and use CloudBerry, you can have a rule to set the Content-type for plist extension's automatically. I use this for iOS files and it works great. I dont have to remember to set it each time.
Greg