When a managed file form element is added to a form with multiple files allowed, once files have been added, it will display a remove selected button. The issue is that this remove button is also a submit button and the javascript triggers all elements with the .js-form-submit class. This means then when you upload another file, it triggers both the upload button and the remove button, resulting in two temporary file entities being created with the same URI. When you hit save, only one of these is marked as permanent, meaning that once the cron job runs, it deletes the temporary file, which results in the permanent filename being deleted from the system.

The code needs updating to target specifically the upload button. I'm just about to submit a patch.

Files: 
CommentFileSizeAuthor
#2 2884052.patch1.28 KBcharlotte.b

Comments

charlotte.b created an issue. See original summary.

charlotte.b’s picture

charlotte.b’s picture

Status: Active » Needs review
cilefen’s picture

cilefen’s picture

We define the loss of stored data as critical. There are a handful of issues related to file deletion that I've related to this issue.

swentel’s picture

Does it really need to be a custom form ? It would explain a couple of issues in the queue already with sudden (sometimes random) deletion of files, very nice find!

swentel’s picture

Issue tags: +JavaScript

Tagging so javascript maintainers will see this.

charlotte.b’s picture

It looks as though the bug won't occur on entity fields as the file widget displays the files in a table above the managed file form element, so it shouldn't trigger any of the remove buttons.

droplet’s picture