Closed samsonasik closed 5 years ago
@samsonasik First: the problem is not zend-form.
The current validators like Size
or MimeType
can not handle the PSR7 uploads.
And then there are two options for zend-filter missing:
stream_factory
:upload_file_factory
:Compare with documentation of zend-filter: "Handle a PSR-7 uploaded file"
@froschdesign ok, thank you.
@samsonasik For the moment, you still need to use the workaround.
@samsonasik Please run a Composer update and check again! (https://github.com/zendframework/zend-validator/releases/tag/release-2.12.0)
@froschdesign I can verify that upload and rename itself working now. However, when calling $form->getData()
, with zend-diactoros
request,, it got the following data:
array (size=1)
'filename' =>
object(Zend\Diactoros\UploadedFile)[966]
private 'clientFilename' => string 'Untitled-1.png' (length=14)
private 'clientMediaType' => string 'image/png' (length=9)
private 'error' => int 0
private 'file' => null
private 'moved' => boolean false
private 'size' => int 761087
private 'stream' =>
object(Zend\Diactoros\Stream)[967]
protected 'resource' => resource(12, stream)
protected 'stream' => string '/Users/samsonasik/www/expressive-fileprg-tutorial/public/uploads/Untitled-1_5c51c49e1d0855_97287659.png' (length=103)
When using Psr7ServerRequest::toZend($request)
, it got the following:
array (size=1)
'filename' =>
array (size=5)
'name' => string 'Untitled-1.png' (length=14)
'type' => string 'image/png' (length=9)
'size' => int 761087
'tmp_name' => string '/Users/samsonasik/www/expressive-fileprg-tutorial/public/uploads/Untitled-1_5c51c49e1d0855_97287659.png' (length=103)
'error' => int 0
Is there something todo in the Form->getData()
for it so the values of form->getData()
consistent for it (using array values)?
@samsonasik
zend-form does nothing here. The return value is created by the filter, in your case the RenameUpload
filter.
My suggestion: You should create a new feature request for the RenameUpload
filter that the user can specify the return type for the filter.
@froschdesign Thank you. I do this to convert it to array for now:
use Psr\Http\Message\UploadedFileInterface;
$data = $form->getData();
\array_walk_recursive($data, function (& $value) {
if ($value instanceof UploadedFileInterface) {
$value = [
'name' => $value->getClientFilename(),
'type' => $value->getClientMediaType(),
'size' => $value->getSize(),
'tmp_name' => $value->getStream()->getMetadata('uri'),
'error' => $value->getError(),
];
}
});
I'm trying latest
zend-validator
2.11.0 and latestzend-inputfilter
2.9.0 which have psr7 support. I'm trying the followingForm::setData()
andForm::isvalid()
. So, the following code:I got the following errors:
I have the following form specs:
When I try remove the validators, the filters got errors:
The current workaround is by using the zend-psr7bridge :