I am using VichUploaderBundle to upload images to AmazonS3 in symfony-2.
I have followed this documentation https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/index.md and created my entity class.
So I have a setter method in the entity
/**
* @param UploadedFile $file
*/
public function setFile(File $file = null)
{
$this->file = $file;
$this->updated = new \DateTime();
}
The client (This is a web application) will be sending the image in base_64 format. So I dont understand how will i get a FILE object out of that string? (Since the parameter of setter method is FILE)
You can use the
UploadedBase64EncodedFile
class from the hshn/base64-encoded-file library:Ok so first you need to save the image to a temporary file - here is a solution for that: How to save a PNG image server-side, from a base64 data string
Then you need to create an instance of an UploadedFile using that file, kind of like this example: https://github.com/dustin10/VichUploaderBundle/issues/203
And then send this UploadedFile to your setFile() method.