【发布时间】:2019-04-16 20:33:12
【问题描述】:
我的问题是,当我尝试使用 VichUploadBundler 和 sonata-admin 上传 mp3 文件时,上传文件时出现以下错误。
"The file "" was not found"
我已经在我的项目中有另一个表单,我在其中上传了一些图像并且我对它们没有任何问题,所以我很震惊,因为我认为音频文件会更容易
这是我的实体文件
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="episode_audio", fileNameProperty="audioName")
*
* @var File
*/
private $audioFile;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $audioName;
/**
* @ORM\Column(type="datetime")
*
* @var \DateTime
*/
private $updatedAt;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $audioFile
*/
public function setAudioFile(?File $audioFile = null): void
{
$this->audioFile = $audioFile;
if (null !== $audioFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getAudioFile(): ?File
{
return $this->audioFile;
}
public function setAudioName(?string $audioName): void
{
$this->audioName = $audioName;
}
public function getAudioName(): ?string
{
return $this->audioName;
}
我的 vich_uploader.yaml 文件
vich_uploader:
db_driver: orm
mappings:
..//
episode_audio:
uri_prefix: /audio
upload_destination: '%kernel.project_dir%/public/audio/'
delete_on_update: true
delete_on_remove: true
inject_on_load: true
最后是我的管理课
protected function configureFormFields(FormMapper $formMapper) {
$formMapper
->add('audioName')
->add('audioFile', VichFileType::class, [
'label' => 'Audio'
]);
}
我只是希望能够在我的文件夹中看到我的音频文件,就像图像一样,我很确定这很愚蠢,如果你们需要在我的代码中看到其他内容,请问我可以更新问题
【问题讨论】:
-
文件顶部有你的 * @ApiResource() 文档块吗?
-
抱歉我的无知,@ApiResource 是什么?无论哪种方式我都没有将它用于图像,它工作得很好。加上我没有使用任何 API
-
我认为
updatedAt不见了 -
我刚刚将该字段添加到我的实体中,但它仍然给我同样的错误,它一定是别的东西
标签: php symfony4 sonata-admin vichuploaderbundle