When an AWS S3 video link prompts a download instead of playing directly in the browser, it’s usually due to the Content-Disposition
header being set to attachment
rather than inline
. The Content-Disposition
header tells the browser how to handle the file. If it’s set to attachment
, the file will be downloaded, whereas inline
will attempt to display the content in the browser.
Solution: Update the S3 Object’s Metadata
You can change the Content-Disposition
header of your S3 object to inline
. Here’s how you can do it:
1. Using the AWS Management Console:
- Navigate to the S3 bucket where your video is stored.
- Find and select the video file.
- Go to the “Properties” tab.
- Under “Metadata”, click “Edit Metadata”.
- Add a new metadata entry with:
- Key:
Content-Disposition
- Value:
inline
- Key:
- Save the changes.
2. Using AWS CLI:
You can also use the AWS CLI to update the metadata:
aws s3 cp s3://your-bucket-name/your-video-file.mp4 s3://your-bucket-name/your-video-file.mp4 --metadata-directive REPLACE --content-disposition "inline"
Replace your-bucket-name
and your-video-file.mp4
with your actual bucket name and video file name.
3. Using AWS SDK:
If you’re managing this via code, you can use the AWS SDK to set the Content-Disposition
when uploading the file:
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
const params = {
Bucket: 'your-bucket-name',
Key: 'your-video-file.mp4',
ContentDisposition: 'inline',
Body: videoFileStream // the file data here
};
s3.upload(params, function(err, data) {
if (err) {
console.log("Error", err);
} if (data) {
console.log("Uploaded in:", data.Location);
}
});
After updating the Content-Disposition
to inline
, your video should play directly in the browser instead of downloading.