weixin_39746869
weixin_39746869
2020-12-29 04:11

Use two upload zones

Hi, I am using this bundle with Dropzone. What I am wondering now is how to use two: - one to upload only images and - another one to upload only documentation (doc, pdf, ...).

How can I handle this?

Thanks in advance.

该提问来源于开源项目:1up-lab/OneupUploaderBundle

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

9条回答

  • weixin_39818521 weixin_39818521 4月前

    You can use more than one mapping.

     yaml
    # app/config/config.yml
    
    oneup_uploader:
        mappings:
            images:
                frontend: dropzone
            documents:
                frontend: dropzone
    

    Be sure to set the correct endpoint in your templates:

    
    {{ oneup_uploader_endpoint('images'); }} #for image uploads
    {{ oneup_uploader_endpoint('documents'); }} #for document uploads
    
    点赞 评论 复制链接分享
  • weixin_39746869 weixin_39746869 4月前

    Thanks for the quick response.

    Perfect. But my question now is: How can I control that in the first one only images are allowed to be uploaded and in the second one only documents (no images)?

    Thank you again.

    点赞 评论 复制链接分享
  • weixin_39818521 weixin_39818521 4月前

    Take a look at the configuration reference. You can use the built in mime type validators:

     yaml
    # app/config/config.yml
    
    oneup_uploader:
        mappings:
            images:
                frontend: dropzone
                allowed_mimetypes: ["image/gif", "image/jpeg", "image/png", ...]
            documents:
                frontend: dropzone
                allowed_mimetypes: ["application/pdf", ...]
    

    Note:

    Do not use allowed_extensions or disallowed_extensions. These are legacy options and will be removed.

    点赞 评论 复制链接分享
  • weixin_39746869 weixin_39746869 4月前

    Oh that's great!! because I am using Dropzone.js and it also gives you the option to filter type, but I am calling it for images and documents, and I couldn't do it. Your solution is perfect.

    The last problem I have is that I am using dropzone.css for both, and I need different views for each one. Could you help me with this?

    Thanks!

    点赞 评论 复制链接分享
  • weixin_39818521 weixin_39818521 4月前

    I'm afraid this does not lie within the scope of this bundle. But the CSS file assigns its rules to the class .dropzone. Why don't you just set two different classes for the two dropzones and style them accordingly?

    Anything that is not about the backend part, should be asked either on the dropzone repo if it is an issue or Stackoverflow for questions. :)

    点赞 评论 复制链接分享
  • weixin_39746869 weixin_39746869 4月前

    Ok, y have changed the css and it works perfect!

    Also, I have changed the allowed types in app/config/config.yml and the files that are not specified there are not uploaded, but when I execute it in chrome, for instance (remember, I am using dropzone.js) looks like it has been uploaded (it shows a green tick). That's why I need to use different dropzone.js for each uploader zones, so I can specify in them the allowed types.

    点赞 评论 复制链接分享
  • weixin_39532628 weixin_39532628 4月前

    Thanks for the bundle, I have got everything working until now on blueimp. I have added an additional input field(selection) as to let the me choose the type(group1, group2) of the image for database entry no folder change. I havent been able to get the value of the selected in the EventListener.

    点赞 评论 复制链接分享
  • weixin_39610422 weixin_39610422 4月前

    I followed the instructions above but I have the following error: 'An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_uploader_upload_documents" as such route does not exist.")'

    This is my code: oneup_uploader: mappings: documents: frontend: blueimp namer: acme_demo.custom_namer gallery: frontend: blueimp allowed_mimetypes: ["image/gif", "image/jpeg", "image/png"]

    In the routing.yml is the following: oneup_uploader: resource: . type: uploader

    In my twig: {{ oneup_uploader_endpoint('documents') }}

    I tried also to substitute "documents" with "images" but it seems it takes only "gallery". Any idea?

    点赞 评论 复制链接分享
  • weixin_39610422 weixin_39610422 4月前

    Ok, I've found the solution. I had to clear the cache, even if it seems weird to me, maybe because when symfony2 imports the config.yml into config_dev.yml it retrieves the copy from the cache instead of the original copy just modified. The bundle is very good ;-)

    点赞 评论 复制链接分享

相关推荐