我正在尝试将 dropzone 与 1up-lab/OneUploaderBundle 一起使用。上传运行良好,我正在尝试使用我的自定义命名器。我的配置:
oneup_uploader:
mappings:
products:
namer: app.upload_namer
use_orphanage: true
frontend: dropzone
storage:
directory: "%kernel.root_dir%/../data/products/"
服务配置
app.upload_namer:
class: AppBundle\Uploader\Naming\UploadNamer
arguments: ["@security.token_storage"]
我的名字:
class UploadNamer implements NamerInterface
{
private $tokenStorage;
private $productName;
public function __construct(TokenStorage $tokenStorage){
$this->tokenStorage = $tokenStorage;
}
/**
* Creates a user directory name for the file being uploaded.
*
* @param FileInterface $file
* @return string The directory name.
*/
public function name(FileInterface $file)
{
$userName = $this->tokenStorage->getToken()->getUser();
return sprintf('%s/%s.%s',
$userName,
uniqid(),
$file->getExtension()
);
}
}
我需要将文件夹名称 ($productName) 传递给我的命名器,以便我可以使用它来创建存储文件夹:
products/$userName/$productName/$filename.ext
这个变量将来自我的表单:
formData.append("productName", "loremipsum");
如何从我的 Namer 中检索此参数?
谢谢!