![](/img/trans.png)
[英]Passing file name from UploadNamer to UploadListener in Symfony v4.1 with OneUpUploaderBundle
[英]How to configure OneUpUploaderBundle and OneUpFlysystemBundle to work in Symfony 4.1
我正在嘗試使用OneUpUploaderBundle
和OneUpFlysystemBundle
Syfony 4.1
。
我的配置在Symfony 3.4
運行良好但是使用Symfony 4.1
我無法弄清楚如何在我的控制器代碼中注入OnUpUploaderBundle。
OneUpUploader.yaml
oneup_uploader:
mappings:
gallery:
storage:
type: flysystem
filesystem: oneup_flysystem.gallery_filesystem
frontend: blueimp
enable_progress: true
namer: app.upload_unique_namer
max_size: 104857600
OneUpFlysystem.yaml
oneup_flysystem:
adapters:
my_adapter:
local:
directory: '%kernel.root_dir%/../data'
filesystems:
default_filesystem:
adapter: my_adapter
alias: League\Flysystem\Filesystem
服務的一部分.yaml
app.upload_listener:
class: App\EventListener\UploadListener
arguments: ['@doctrine.orm.entity_manager', '@session', '@service_container']
tags:
- { name: kernel.event_listener, event: oneup_uploader.pre_upload.gallery, method: onUpload }
- { name: kernel.event_listener, event: oneup_uploader.post_upload.gallery, method: onPostUpload }
app.allowed_mime_type_listener:
class: App\EventListener\AllowedMimeTypeValidationListener
arguments: ['@service_container']
tags:
- { name: kernel.event_listener, event: oneup_uploader.validation.gallery, method: onValidate }
app.upload_unique_namer:
class: App\Uploader\Naming\UploadUniqueNamer
arguments: ['@service_container']
public: true
// SEE sections ERROR 1 and ERROR 2
// FOR relevant config details
oneup_flysystem.gallery_filesystem:
class: [...]
public: true
// previously, to reference upoad root path node
// i could just write following in controller and it worked
$filesystem = $this->get('oneup_flysystem.gallery_filesystem');
$complete_file_path = $ultraHelpers->getDownloadableFilePath($file_id);
$exists = $filesystem->has($complete_file_path);
// Now i am stumped how to get the same effect in symfony 4.1
如果像我這樣修改我的服務
oneup_flysystem.gallery_filesystem:
class: League\Flysystem\FilesystemInterface
public: true
當前錯誤
無法實例化接口League \\ Flysystem \\ FilesystemInterface
如果像我這樣修改我的服務
oneup_flysystem.gallery_filesystem:
class: League\Flysystem\Filesystem
public: true
當前錯誤
(1/1)RuntimeException無法自動裝配服務“oneup_flysystem.gallery_filesystem”:方法“League \\ Flysystem \\ Filesystem :: __ construct()”的參數“$ adapter”引用接口“League \\ Flysystem \\ AdapterInterface”但不存在此類服務。 您應該將此接口別名為現有的“oneup_flysystem.my_adapter_adapter”服務。
好像你錯過了配置中的縮進。 嘗試改變它
filesystems:
default_filesystem:
adapter: my_adapter
alias: League\Flysystem\Filesystem
正確的配置:
oneup_flysystem.gallery_filesystem:
alias: League\Flysystem\Filesystem
public: true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.