bolt / core

🧿 Bolt 5 core
https://boltcms.io
MIT License
539 stars 159 forks source link

Upload zip files not allowed #2479

Open peterboorsma opened 3 years ago

peterboorsma commented 3 years ago

The drag 'n drop file uploader in /bolt/filemanager/files does not accept zip files while zip is in the accept_file_type list

accept_file_types: [ twig, html, js, css, scss, gif, jpg, jpeg, png, ico, zip, tgz, txt, md, doc, docx, pdf, epub, xls, xlsx, ppt, pptx, mp3, ogg, wav, m4a, mp4, m4v, ogv, wmv, avi, webm, svg, webp, avif]

In order to be able to upload zip files you have to add the extension to the accept_media_types array. I find this confusing because zip is not a media typ IMO

accept_media_types: [ gif, zip, jpg, jpeg, png, svg, pdf, mp3, tiff, avif, webp ]

Above accept_file_type config.yaml states:

# Define the file types (extensions to be exact) that are acceptable for upload
# in either file fields or through the files screen. 

But that's not correct apparently. So what is the difference between `accept_file_type` and `accept_media_types`?

Details

Bolt 4.1.15

System Information:

Install type: Packaged distribution
Database: mysql 5.5.5-10.5.9-MariaDB - 127.0.0.1 via TCP/IP
PHP version: 7.3.27
Symfony version: v5.2.5
Operating System: Linux - 2.6.32-042stab136.1
Assets version: 4.1.14

Reproduction

If you're filing a bug, please describe how to reproduce it. Include as much relevant information as possible, such as:

Bug summary

Specifics

Steps to reproduce

Expected result

Actual result

I-Valchev commented 3 years ago

hi @peterboorsma, yes this is definitely a bug, but a tricky one. Here's a few details:

  1. The acceptedFileTypes are set correctly here: https://github.com/bolt/core/blob/4.1/src/Controller/Backend/Async/UploadController.php#L82

  2. The bug appears when Bolt is trying to create a Media entity here: https://github.com/bolt/core/blob/4.1/src/Controller/Backend/Async/UploadController.php#L118

  3. Right now, the MediaFactory only allows media file types (which, sort of makes sense) https://github.com/bolt/core/blob/4.1/src/Factory/MediaFactory.php#L47

If we simply add the file types to the MediaFactory, there will be no distinction between the accept_media_types and accept_file_types, which also doesn't sound like the right approach.

🤷‍♂️ @bobdenotter any ideas?