Yii2: Proposal: Provide an interface for UploadedFile

Created on 27 Sep 2016  路  8Comments  路  Source: yiisoft/yii2

If client sends files in a way that PHP does not handle natively (via $_FILES) it would be a problem to validate them using FileValidator.

My case was uploading photos via JSON API. To send a photo, client encodes it with base64 and puts as a prop to the request body. There's two options how to handle this request. The first one is to do it manually and the second one is to make an ugly extension of UploadedFile to override $_FILES-specific methods.

Possible similar case is uploading photos by link.

I encourage everyone to share their experience and thoughts about this topic.

enhancement

Most helpful comment

I think it's a good idea.

All 8 comments

It would solve my issues as well, ive done it the manual way

Is this 3rd party JS or your own?
I had a similar need where I was modifying images client side that would be uploaded so used ajax and FormData. This will save the need for base64 encoding and allow the use of $_FILES.

I think it's a good idea.

@Alex-Code I also suggest to use multipart/form-data if possible. In my case it was not.

Suggest to resolve this issue will be better to move the code responsible for file extraction from UploadedFile to other class that implements extraction strategy.

@Oxyaction is it possible to make it without breaking BC?

Resolved by #14801

Was this page helpful?
0 / 5 - 0 ratings