Problem/Motivation
Most popular operating systems (Windows and macOS) don't extract tar.gz compressed files by default (as far as I am concerned). Some clients have asked us if it would be possible to, when downloading uploaded files from webform results, have a file compressed as a ZIP instead.
Proposed resolution
Add functionality to provide user the ability to choose tar.gz or zip as type of compressed file for results' uploaded files.
User interface changes
In terms of user interface, I believe that, when user checks the checkbox "Download uploaded files", a pair of radio buttons should show up asking what type of compressed file to be used, tar.gz or zip.
Thank you.
Mauricio
Comments
Comment #2
jrockowitz commentedI think this might be possible because Drupal core does support zip files but it is going to require some major refactoring.
The webform module's exporter is hardcoded to manipulate only Tar files. The code was written several years ago and I was probably not able to get Zip archiving working at the time.
Comment #3
jrockowitz commentedSo Drupal's support for ZIP and even TAR is not great.
I decided to write the below code snippet that shows how to create the needed ZIP or TAR archive for webform submissions export.
The next step would be to refactor the \Drupal\webform\WebformSubmissionExporter to use a custom service or helper that supports creating TAR and ZIP archives.
Comment #4
jrockowitz commentedI think below are the four helper methods that need to be added to the WebformExporterInterface.
\Drupal\webform\Plugin\WebformExporterBase::getArchive();
\Drupal\webform\Plugin\WebformExporterBase::addArchiveDirectory($directory, $name, $remove_path);
\Drupal\webform\Plugin\WebformExporterBase::addArchiveFile($file, $name, $remove_path);
\Drupal\webform\Plugin\WebformExporterBase::addArchiveString($text, $name);
Comment #6
jrockowitz commentedThe attached patch refactors the webform exporter's archive support to make it possible to support ZIP archives.
Next steps
Comment #9
jrockowitz commentedIf all the tests pass, this patch can be reviewed.
Comment #12
jrockowitz commentedComment #16
jrockowitz commentedComment #18
jrockowitz commentedComment #19
jrockowitz commentedBelow are my steps for manually testing this change.
Comment #21
jrockowitz commentedI committed the patch. Please download the latest dev release to review.
Comment #23
mogio_hh commentedSorry to be a pain. Could somebody guide me to the exact location where I could set, that users have the option to download the uploaded files of a submission as an archive?
I could not find it in the settings. Also I am a little bit confused we talk here about downloading all submissions instead of the uploaded files of 1 submission. Wasn't the issue poster asking for "uploaded files". Misunderstanding on my side?
Comment #24
jrockowitz commentedComment #25
mogio_hh commentedThank you!
Still not what I expected. Is it possible to create a zip + download link for the uploaded files of a webform submission, instead of having the client to download each file individuell?
In a perfect world the generated email with the data of the submission would provide the url to the zip. So clients don't have to download the files one by one.
Was this ever planed or is it necessary to patch webform?
Comment #26
jrockowitz commentedProviding a zip of uploaded files would need to be handled via custom code or a dedicated contrib module.
Comment #27
Monster971Hello,
I am interested in the subject but I did not really understand.
Indeed I wish to be able to offer the possibility of downloading the files submitted by webform in a zip file via a link in a view in a table?
Is it possible to achieve this?
Comment #28
srdtwc commentedI noticed that the UI has the option to select tar.gz or zip, but when you selection zip nothing seems to happen. No errors are displayed. Is this intended functionality?