Skip to content

S3 Bucket links download video files instead of opening in browser

0

Hi, when there is data uplaoded to S3 buckets, for example an MP4, when i upload it directly from S3 and make it public, the public URL opens the video in browser. However when I try to uplaod the same file from my website and sits in the same bucket, the public URL makes the video downloaded when clicked. I don't understand why this happens. How can I make it such that it always opens these links in browser and not downlaod it?

THanks

asked 10 months ago610 views
2 Answers
0

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:

  1. Check the metadata settings when uploading through your website. Make sure the Content-Disposition header is not set to "attachment".

  2. 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".

  3. 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.

  4. 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

answered 10 months ago
EXPERT
reviewed 9 months ago
0

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.

EXPERT
answered 9 months ago
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.