Based on Marius's #865, with some extra checking and a test.
Attach a file by drag & drop or click to upload