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

pbdev's avatar
Level 4

File upload, AWS S3 and mime-type issue

Uploading images on S3 https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/12

I have an issue here

$file = request()->file('avatar')->store('user/avatars');

$full_path = Storage::disk('s3')->url($file);

When you upload an image in this way, 'store' function doesn't tell S3 bucket what mime-type has this image (or file). And when you try to retrieve the uploaded image in the browser by it's URL, a browser will DOWNLOAD (it won't open as users expect) due to incorrect mime-type. By default S3 sets 'application/octet-stream' mime-type.

Does anybody know how to pass mime-type to S3 bucket?

0 likes
8 replies
pbdev's avatar
Level 4

@lars64 The 'store' function uses 'storeAs'

$file = request()->file('avatar')->store('user/avatars');

public function store($path, $disk = null) { return $this->storeAs($path, $this->hashName(), $disk); }

The issue remains, can any body help to resolve this issue?

1 like
jan_zikmund's avatar

@pbdev I would love to know this also. As far as I checked, the problem is in putFileAs() method of /vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php which stream copies the file from temp folder to final location.

Not sure if there is any method to assign MimeType again once the file is copied, but apparently if the image with Mime Type "application/octet-stream" is served as src=".." for the image, FF, Chrome and Safari seem to serve it all good.

EDIT: I found here: http://stackoverflow.com/questions/29298313/images-stored-on-amazon-aws-s3-not-rendered-in-internet-explorer that IE might have problems, but probably that was because the images were missing extension. I just did some tests and they loaded correctly in FF, Chrome, Safari and IE 9,10,11.

So I believe that as long as you serve the image URLs as img src=".." attributes, it should be fine. Still it would be nice having this fixed in the future

1 like
spekkionu's avatar

You can pass an array of options as a second parameter to the store method (or third parameter to the sotreAs method).

You can specify the mimetype using these options.

1 like

Please or to participate in this conversation.