S3 Image Download _verified_ Instead Of Opening In Browser May 2026
const { PutObjectCommand, S3Client } = require("@aws-sdk/client-s3"); const uploadImage = async () => { const command = new PutObjectCommand({ Bucket: "your-bucket-name", Key: "photo.jpg", Body: fileBuffer, ContentType: "image/jpeg", // This line forces the download ContentDisposition: 'attachment; filename="my-cool-photo.jpg"', }); await s3Client.send(command); }; Use code with caution. 4. Method C: Forcing Download via Presigned URLs
If you’ve ever clicked a link to an image stored in an Amazon S3 bucket only to have it open in a new tab instead of downloading to your computer, you aren’t alone. By default, browsers try to render common file types like JPEGs and PNGs directly. s3 image download instead of opening in browser
If you are building an app where users upload photos, you should set this metadata at the moment of upload. Here is a quick example using the : javascript By default, browsers try to render common file
If you want an image to be viewable normally in some places but downloadable in others, don't change the permanent metadata. Instead, override the header when generating a . Instead, override the header when generating a