How to Enable Defaukl File Extesion Upload in Drupal
Problem
When i allow whatever extension on file upload, with multiple upload in that location is a bug with validation extension.
Validation of the get-go file work corretly.
For the second file and other $extensions apply default value = 'jpg jpeg gif png txt doctor xls pdf ppt pps odt ods odp';
Solution
For correct operation, we need to move the lawmaking with the $extensions above "foreach ($uploaded_files "...
I'm attaching a patch.
Back up from Acquia helps fund testing for Drupal
davisbuttephon1999.blogspot.com
Source: https://www.drupal.org/project/drupal/issues/2894193
Comments
Comment #3
dawehner
German
Credit Attribution: dawehner every bit a volunteer commented
Comment #4
Anonymous (non verified) Credit Attribution: Bearding commented
Comment #5
runeasgar Credit Attribution: runeasgar every bit a volunteer commented
touch
: dummy.txt and dummy.ftw.Unable to reproduce. Delight provide step-by-step instructions for reproducing this result.
Annotate #6
Anonymous (not verified) Credit Attribution: Bearding commented
Comment #vii
Anonymous (not verified) Credit Attribution: Anonymous commented
Comment #ix
jlscott Credit Attribution: jlscott equally a volunteer commented
I accept tested and confirmed the patch from #7.
I am using the contrib module allow_all_file_extensions to enable the UI to specify a file field that allows files with any extension to be uploaded. There is no official D8 release yet, but a tarball containing working D8 code is available from https://www.drupal.org/project/allow_all_file_extensions/issues/2974935
My proffer to improve the patch would be to put ALL of the processing of the $validators['file_validate_extensions'] value to a higher place the "foreach file" loop rather than just the portion that checks whether the listing is present but empty. The logic of the block can then exist left unchanged from the original.
Cheers
Test and fix looks good. Already tester this in the other event as well.
One nitpick
Why not test for empty($validators['file_validate_extensions']) instead of commencement element.
Does what the comment says then, and then a bit more readable imo.
Comment #12
alexpott
English
🇪🇺🌍
Credit Attribution: alexpott commented
I remember we should refactor to prevent these type of errors. The problem is the loop. Allow's refactor everything in the loop into a role. This means this type of event is far less likely to occur.
The interdiff attached is non easy to read.
I'thousand not certain that this is the right place for this exam code. Can we not practise something but in the file module?
Comment #13
alexpott
English language
🇪🇺🌍
Credit Attribution: alexpott commented
Here's a test that is simply office of the file module and its existing test infra.
Annotate #xiv
jlscott Credit Attribution: jlscott as a volunteer commented
@alexpott. I like the refactoring yous have done, I converted your patch to allow it to apply to viii.5.4 and have tested it. I can confirm that it works correctly with my surroundings (D8.5.4 and contrib module "allow_all_file_extensions"). Converted patch fastened. leaving on "Needs review" equally I accept not tested your patch in an 8.6 environs.
Comment #17
jlscott Credit Attribution: jlscott as a volunteer commented
Patch for D8.5.4 rerolled and marked as do-non-exam.
@jlscott thanks for backporting to eight.v.x - the patch in #17 doesn't take the new exam. I'g uploading the 8.6.10 patch as nosotros take to get that done first and information technology helps the committers and reviewers when the about recent patch is the i to review / commit.
@jlscott perhaps yous tin review the patch with a view to rtbc?
Crediting @mallezie for work on the indistinguishable issue. Crediting @kkonuhov for creating the issue.
Comment #xx
jlscott Credit Attribution: jlscott as a volunteer commented
I can confirm that the patch in #18 works correctly on my system (D8.6.0-dev plus allow_all_file_extensions).
Just took a look at the new patch. I really similar the dissever office, makes things more than readable. Only constitute some very pocket-sized nitpicks on the comments.
the Uri where the file should be copied to.
If the uploaded file was not saved.
See lowercase
Not sure this annotate makes much sense.
@mallezie all of this documentation is copied from the existing documentation is copied apart from
The created file entity or FALSE if the uploaded file non saved.
and I call up you lot could havewas
,is
or fifty-fifty zip here are it is all still correct :)Then only an extra RTBC from my side. Did non want to change status on those nitpicks, and so thank you a lot for explaining them.
The failed test run had zilch to do with this outcome.
nit: this needs a param comment
are we sure we want to add a new procedural role?
should this be file?
Thanks for the review @larowlan
1. Fixed
2. Yes because it makes these blazon of errors incommunicable to have in this function. It's much easier to understand the responsibilities when _file_save_upload_single() is in a different scope than file_save_upload()
iii. Stock-still.
One niggling Nitpicking: When commenting the setting of permission we should comment consistently that nosotros ready FileUri too earlier that, isn't?
Autonomously from that RTBC from me, since simpletest.me examination with patch applied run successfully and multiple files upload test with different file types worked every bit expected without flaws. Additionally tested with experimental module media library: https://dmb66.ply.st/node/1
Do nosotros need a backport for 8.6.x ?
@diqidoq this code is not introduced on changed by this patch. This patch moves everything from inside a foreach into it'due south own function. As well the patch applies cleanly to viii.vi.x so it'southward upto the committer equally to whether it should be reddish-picked. There's no need for a separate backport patch.
Comment #34
diqidoq Credit Attribution: diqidoq every bit a volunteer and commented
@alexpott: Thanks for taking the time to analyze. Dandy to come across progress on it. Thanks to all who have worked on it. Maybe nosotros become some more than testers for RTBC?
Quite right @diqidoq. Where are my manners. I tested this patch on Friday and it worked beautifully. Attached multiple files, no validation errors!
Comment #41
diqidoq Credit Attribution: diqidoq as a volunteer and commented
1+ @take hold of & @alexpott! Awesome!
Annotate #42
Lendude
Dutch
Amsterdam
Credit Attribution: Lendude commented
Shame these assertions that @alexpott added in #thirteen got taken out in #14, now nosotros have no positive assertions for the error messages, only a negative assertion for the summit level error.
Comment #44
wturrell Credit Attribution: wturrell as a volunteer commented
Howdy. I'm comparing this and the patch in #2869855: Race condition in file_save_upload causes data loss - practise the changes to validation here brand the latter unnecessary now? (and if not, might someone exist able to help with re-rolling it?)
What I noticed was the chunk of identical lawmaking in
file.module:1039
(building the render assortment for the error message, which is the primary part of the race condition patch).