barryvdh / elfinder-flysystem-driver

elFinder driver for Flysystem
183 stars 41 forks source link

Content type gets set to binary/octet-stream for images uploaded to S3 via elfinder-flysystem-driver #8

Closed aaronblondeau closed 9 years ago

aaronblondeau commented 9 years ago

I am working on a Laravel 5 site using barryvdh/laravel-elfinder along with Glide on Amazon S3. I was unable to get glide to work at all with elfinder until I discovered that all uploaded images were being stored in S3 with content type "binary/octet-stream".

I was finally able to resolve the problem by modifying the _save function in elFinderVolumeFlysystem.php. I changed this line :

if ($this->fs->putStream($path, $fp)) {

to

if($this->fs->put($path, stream_get_contents($fp))) {

I think that storing the entire file contents instead of the stream allows flysystem to accurately guess the mime type. There is probably a better way to accomplish this, so I wanted to submit an issue for your consideration.

barryvdh commented 9 years ago

This is probably related to this: https://github.com/thephpleague/flysystem/issues/34

So we need to set the mimetype for S3, but then we can't use the streams because we need to read the file before uploading.. Not sure what is best.

barryvdh commented 9 years ago

Actually, according to this: https://github.com/aws/aws-sdk-php/issues/138 It should guess the mime based on the filetype. Not sure why that's not picked up.

barryvdh commented 9 years ago

I guessed the mimetype based on the upload filename. Should provide better results without much impact, because it doesn't have to read the entire file.

Let me know if this solves your issues!

aaronblondeau commented 9 years ago

This change resolved the issue - thanks!