Rework file upload for #360 and #361