我正在使用VichUploaderBundle将图像上传到symfony-2中的AmazonS3。
我遵循这个文档https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/index.md并创建了我的实体类。
因此,我在实体中有一个setter方法
/**
* @param UploadedFile $file
*/
public function setFile(File $file = null)
{
$this->file = $file;
$this->updated = new \DateTime();
}客户端(这是一个web应用程序)将以base_64格式发送图像。所以我不明白如何从字符串中获取文件对象?(由于setter方法的参数为FILE)
发布于 2016-10-14 22:41:53
您可以使用hshn/base64-encoded-file库中的UploadedBase64EncodedFile类:
use Hshn\Base64EncodedFile\HttpFoundation\File\Base64EncodedFile;
use Hshn\Base64EncodedFile\HttpFoundation\File\UploadedBase64EncodedFile;
$uploadedFile = new UploadedBase64EncodedFile(
new Base64EncodedFile($base64String)
);
$uploadableEntity->setFile($uploadedFile);发布于 2015-10-15 18:15:16
好的,首先你需要将图片保存到一个临时文件中--这里有一个解决方案:How to save a PNG image server-side, from a base64 data string
然后,您需要使用该文件创建一个UploadedFile实例,类似于下面的示例:https://github.com/dustin10/VichUploaderBundle/issues/203
然后将这个UploadedFile发送给您的setFile()方法。
https://stackoverflow.com/questions/33103335
复制相似问题