cakephp-upload
cakephp-upload copied to clipboard
add base64 upload
Settings to use it
'pathProcessor' => Base64Processor::class,
'base64_extension' => '.jpg',
'transformer' => Base64Transformer::class,
'uploadValidator' => Base64UploadValidator::class,
@josegonzalez suggestions on how I could get rid of is_string()
and isset()
On base64 we just get a long string of data with no filename, no type, no size.
Type and size column will also not be set.
Needs tests before I'll review, sorry.
@josegonzalez I added unit tests
Looks like some code style fails. I will fix it later today.
@josegonzalez could you review, please?
I'm not quite sure why this functionality needs to be added to the core? Who will want to use this?
To me this is an edge-case and could be implemented with custom classes in userland code base.
I think you are right.In this case, we can close the pull.
Could be useful. Can we get documentation for this?
@josegonzalez before getting the doc for this, we should decide what to do with the type and the size, right now they are not supported and if we are ok with https://github.com/FriendsOfCake/cakephp-upload/pull/495/files#diff-84c66ea1e7013949dabde1157612da57R103
After some googling
Filesize:
strlen(base64_decode($data));
Filetype:
$f = finfo_open();
$mime_type = finfo_buffer($f, $data, FILEINFO_MIME_TYPE);
Those seem reasonable to me @jorisvaesen.
The problem is not how to determine the file size and type, is where do we put that code that does this?
We could have a FileProcessor
or something that represents how to get that data for each type of file upload?
That will solve one problem.
How about this if
https://github.com/FriendsOfCake/cakephp-upload/pull/495/files#diff-84c66ea1e7013949dabde1157612da57R103
Are you ok with having this if
or is better to make another interface?
@mma can you add actual usage docs for this so I can see how we plan on presenting it's use for users? That'll give me a better idea of what the internals should look like.
Adding a FileProcessor interface and a FileProcessor option to the config seems to me the right thing to do. Just make sure that this config option allows a callback function so an user can return the right processor based on the upload (base64, php file upload, ...)
@josegonzalez Sure, I will add the docs this week.
The problem is not how to determine the file size and type, is where do we put that code that does this?
It should be in validation methods shouldn't it?
I don't think it should be in validation.We want to use the methods to get the actual size and file type https://github.com/FriendsOfCake/cakephp-upload/pull/495/files#diff-84c66ea1e7013949dabde1157612da57R123 so that we can set on the entity.
Just FYI, how I provide cropping feature is use js code to just generate the cropping dimensions and submit it in a separate field without touching the actual upload file. Then use the cropping data to crop on server side.
Only drawback of this way is the full image is uploaded but in return it saves all the extra code for handing base64 encoded data and more importantly upload validation.
I don't think it should be in validation.
If not in validation then how can I prevent someone from submitting a non image base64 encoded data?
We can provided a method in ImageValidationTrait.php that uses https://secure.php.net/manual/en/function.imagecreatefromstring.php
Unless cake's validator can be used to validate the mime type of base64 encoded data before any other processing begins, I am a big "NO" on adding this feature to the plugin.
When you say cake's validators
you talk about the validators already provided by cake or the custom validators?
Custom validation methods which will be used by Cake's Validator
:slightly_smiling_face:
@ADmad could you take a look over the validator when you have some time?
It is very useful, I also really need it. I am very supportive of this.