I have a node-type with a multi-valued filefield. If the user clicks "add another item" prematurely, then duplicate copies of the file get uploaded to the server.

Specifically, suppose the user wishes to upload two files.

Scenario #1: The patient user

She uploads the first file ("a.flv"). She then waits for this file to finish uploading before clicking "add another item". She then uploads the second file ("b.flv").
Result: Two files get uploaded to the local server ("a.flv" and "b.flv"). The 'files' database table contains two corresponding entries, with 'status' set to 1.

Scenario #2: The trigger-happy user

She uploads the first file ("a.flv"). Before the upload finishes, she clicks "add another item". She then uploads the second file ("b.flv").
Result: Three files get uploaded to the local server ("a.flv", "a_0.flv" and "b.flv"). The files "a.flv" and "a_0.flv" are identical. The 'files' database table contains three corresponding entries. The 'status' field is 0 for "a.flv", and is 1 for "a_0.flv" and "b.flv".

I realize this may be hard to fix, and if so I am wondering whether it might be possible to prevent the trigger-happy user from prematurely clicking "add another item", by disabling any such buttons during file-upload.

Thanks very much!

- Mindy

Comments

markconroy’s picture

What I normally do is count how many files I need to upload, then click on "Add another Item", wait for the input field to load, then click on it again, etc. until I have all the fields I want. Next, I add the files to each field and then I click "upload" beside each. It's slightly slower, but works. At the moment, I have a page uploading 24 images to a gallery I am creating. I can just leave it and surf these forums while it's doing its thing.

quicksketch’s picture

Yeah, unfortunately this is by-design behavior of FileField. It's not really optimal, but it's the structure that we're stuck with in our current architecture. We could disable the filefields when the "Add another item" button is clicked to prevent the browser from sending the files to the server (this is what we do when you have multiple filefields on the same form, to prevent a button from uploading another filefield's files), but because the entire file field form is replaced when adding another item, it would have the result of deselecting the currently selected file. Security restrictions within browsers prevent us from being able to set a default value on a file field.

So basically without rearchitecting the module, there's no way to fix this. At this point in the D6 cycle, we're only maintaining the module, not rebuilding it, so it's unlikely this will be changed for D6. Unfortunately it's the same way in D7, so you'll have to endure it there too. It's finally getting fixed in D8 with HTML5's ability to upload multiple files at the same time in #625958: Support Uploading Multiple Files for HTML5 Browsers via #multiple attribute.

quicksketch’s picture

Sorry I didn't read the whole post.

I realize this may be hard to fix, and if so I am wondering whether it might be possible to prevent the trigger-happy user from prematurely clicking "add another item", by disabling any such buttons during file-upload.

That seems like it could be doable. I don't have any D6 sites remaining at this point, so I'm happy to look at patches for this functionality but I won't undertake it myself.

markconroy’s picture

You could try "Multiupload File Field widget" and "Multiupload Image field widget"

http://drupal.org/project/multiupload_filefield_widget

I find those two modules very handy these days, though are Drupal 7 only.

markconroy’s picture

Issue summary: View changes

Clarification