- Newest
- Most votes
- Most comments
When accessing video files from an S3 bucket, whether they open in the browser or download depends on several factors, including how the content is being served and the headers that are sent with the response.
The difference you're experiencing between uploading directly to S3 versus through your website likely relates to the Content-Disposition header that's being set when the file is uploaded. When you upload through your website, your application might be setting this header to "attachment", which instructs browsers to download the file rather than display it.
Here are some ways to ensure videos open in the browser instead of downloading:
-
Check the metadata settings when uploading through your website. Make sure the Content-Disposition header is not set to "attachment".
-
When uploading via your application, explicitly set the Content-Type to "video/mp4" and either don't set Content-Disposition or set it to "inline".
-
Consider using Amazon CloudFront in front of your S3 bucket. This not only improves load times for videos but also gives you more control over response headers.
-
For better video streaming performance overall, consider implementing a CDN like CloudFront with your S3 bucket. This would improve load times and provide a better viewing experience for your users.
If you're still experiencing issues, you might need to examine how your website's upload functionality is configuring the metadata for the files it uploads to S3.
Sources
How to Open an Excel File Stored in S3 in a Web Browser? | AWS re:Post
Hosting videos in S3 bucket | AWS re:Post
As mentioned by repost agent, you need to explicitly set the Content-Type to "video/mp4" and either don't set Content-Disposition or set it to "inline". Here's how you can do it,
For existing videos,
aws s3 cp s3://your-bucket-name/video.mp4 s3://your-bucket-name/video.mp4 \
--metadata-directive REPLACE \
--content-type video/mp4 \
--content-disposition inline
For new videos,
aws s3 cp video.mp4 s3://your-bucket-name/video.mp4 \
--metadata-directive REPLACE \
--content-type video/mp4 \
--content-disposition inline
If there are lot of videos, you can configure a batch operation to update all the metadata of the videos.
Relevant content
- asked 3 years ago
- asked 2 years ago
- asked 3 years ago
