我试图在1up-lab / OneupUploaderBundle中使用dropzone。 上传工作正常,我正在尝试使用自定义名称。 我的配置:
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");
如何从命名器中检索此参数?
谢谢!