Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wesmahler's avatar

How do you upload a file to s3 and set the content-type?

When uploading a .csv file to S3, it doesn't set the Content-Type to text/csv.

When the file is opened in the browser, it doesn't prompt for download. How can we set the content type correctly so it starts the file download?

0 likes
4 replies
Cronix's avatar
Cronix
Best Answer
Level 67

This looks better:

Storage::disk('s3')->put($fileName, $file, [
    'visibility' => 'public',
    'mimetype' => 'text/csv'
]);
3 likes
Tony-515's avatar

Hi, Cronix. Thanks for your valuable post, I just tried it with svg file. But I got this error message in aws side. could you assist me?

Aws\S3\Exception\S3Exception: Error executing "PutObject" on "https//mydomain/filepath/"; AWS HTTP error: Client error: resulted in a 400 Bad Request response:

Please or to participate in this conversation.