phpsymfonyvichuploaderbundle

Symfony2: manual file upload with VichUploaderBundle


How can I upload file with VichUploaderBundle without form?

I have file in some directory (for example web/media/tmp/temp_file.jpg)

If I try this:

$file = new UploadedFile($path, $filename);

$image = new Image();
$image->setImageFile($file);

$em->persist($image);
$em->flush();

I've got this error:

The file "temp_file.jpg" was not uploaded due to an unknown error.

I need to upload file from remote url. So I upload file to tmp direcotry (with curl) and then I keep trying to inject it to VichUploadBundle (as you can see above).


Solution

  • Short answer: VichUploaderBundle does not support uploading files without using Symfony Form component.

    I need to upload file from remote url. So I upload file to tmp direcotry (with curl) and then I keep trying to inject it to VichUploadBundle (as you can see above).

    In that case, you don't need to upload, you need to download. And that's not what VichUploaderBundle is meant to do.