Preventing empty uploads

Archived from the Transloadit support forum. Originally posted on November 22, 2011; details may be outdated, see our docs for current behavior. Original thread

I’m curious if it’s possible to prevent empty uploads with the jQuery plugin. If a file field has no file selected, why is it attempting to upload and process an empty file to Transload.it? In my app, when a user edits a resource but chooses not to change the attached image then an empty file is uploaded and ends up replacing the existing image. Obviously, I could handle this empty result on my backend, but I’d rather just get to the root and have the form submitted without any transloadit interaction when it’s unnecessary.

This seems like a bug. That is, we shouldn’t overwrite your images with an empty upload. Can you point to an assembly id where this occurs?

I’m sorry, I think I misspoke. My attachments aren’t getting overwritten, but the transloadit modal still pops up when there is no file in a file field, which still results in an assembly being created. It also means the moment a user clicks submit on a form with a file field they have to wait an extra few seconds for the jquery plugin to upload empty data. As an example, visit http://transloadit.com/demos/image-resize/resize-to-75x75 and simply press “Upload”. What I would prefer to see in the case of that example is that the jQuery plugin is never engaged if the file field is empty. I’ve tried attaching the jQuery plugin conditionally on the form’s submit event, but it doesn’t seem to work.

Is it possible for the jQuery plugin to just let a form submit normally if the file field is empty?

Is it possible for the jQuery plugin to just let a form submit normally if the file field is empty?

Yes. But it’s unfortunately not baked into the plugin so you’d have to try a little further.

Tim: Could you have look, IIRC you did something similar before?

Yeah, will take a look today.

I will let you know when I am finished, Adam.

The patch will be merged today.

Hey Adam,

I merged the patch today. Please checkout the blogpost for it: http://transloadit.com/blog/

Let me know how it goes.

Tim

Awesome! Thank you for taking the time to add this feature, Tim. Happy New Year!

You are welcome! Happy new year to you as well!