Skip to content

[5.3] Add mime type to disk storage via UploadedFile#16416

Closed
jodiedunlop wants to merge 4 commits intolaravel:5.3from
jodiedunlop:feature/mimetype_on_filesystem_driver
Closed

[5.3] Add mime type to disk storage via UploadedFile#16416
jodiedunlop wants to merge 4 commits intolaravel:5.3from
jodiedunlop:feature/mimetype_on_filesystem_driver

Conversation

@jodiedunlop
Copy link
Copy Markdown
Contributor

Although mimetype is a supported configuration option for Flysystem, there is no way to pass this though the FileSystemAdapter put() method and consequently any of the convenience functions in UploadedFile. This commit adds support for a mimeType parameter for all of the store functions within UploadedFile and to the Illuminate\Filesystem\FilesystemAdapter class.

Signed-off-by: Jodie Dunlop <jodie.dunlop@rexsoftware.com.au>
@jodiedunlop
Copy link
Copy Markdown
Contributor Author

Store file with image/jpeg mime type:
$uploadedFile->storePublicly('folder', 's3', 'image/jpeg');

Store file with auto mime type (calls getMimeType()) by passing (boolean) true:
$uploadedFile->storePublicly('folder', 's3', true);

@GrahamCampbell GrahamCampbell changed the title Add mime type to disk storage via UploadedFile (storeFile etc.) [5.3] Add mime type to disk storage via UploadedFile Nov 15, 2016
@caiquecastro
Copy link
Copy Markdown
Contributor

I think there is a mistake when passing parameters to storeAs method.

public function store($path, $disk = null, $mimeType = null)
{
return $this->storeAs($path, $this->hashName(), $disk);
return $this->storeAs($path, $this->hashName(), $disk, $mimeType);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following @caiquecastro comment...
There should be a null here before $mimeType, currently you're passing the $mimeType as the $visibility parameter.

@taylorotwell
Copy link
Copy Markdown
Member

taylorotwell commented Nov 29, 2016

I implemented this in Laravel 5.4 by allowing an array of options to be passed to these methods:

Storage::disk('local')->put('something', 'hello world', [
    'visibility' => 'public',
    'mimetype' => 'text/plain'
]);

@martinbean
Copy link
Copy Markdown
Contributor

@taylorotwell Is this functionality not going to be back-ported to Laravel 5.3 then? As it’s a bit awkward having everything sent to S3 with a MIME type of application/octet-stream.

@GrahamCampbell
Copy link
Copy Markdown
Collaborator

No, 5.4 is only a few weeks away anyway. :)

@martinbean
Copy link
Copy Markdown
Contributor

@GrahamCampbell But it’s useful for applications now and not every one will be upgrading to 5.4 on launch day.

@captbrogers
Copy link
Copy Markdown
Contributor

I agree with @martinbean, I had this problem just a few weeks ago. I had to use the AWS SDK directly to allow the mime type to be set while still allowing the file to be streamed instead of uploaded the my server then moved over to S3.

@jrean
Copy link
Copy Markdown
Contributor

jrean commented Jan 24, 2017

Same issue and headache with 5.3

@ingageco
Copy link
Copy Markdown

Same issue with 5.3 - can't upgrade to 5.4 yet due to lack of support from a few packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants