Creating db records that map to uploads

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

Here’s what I’m trying to do:

I have a form with one text area, and one file upload element. I’d like to have the user enter “notes” in the textarea and upload zero or several files. The textarea maps to a table called “projects”. Each project record can have zero or many “project_files”.

What is the best way to setup my form so that if a user enters “notes” a project record is created, and then for each uploaded file, a child “project_files” record is created that maps to the “project” record? I’m using the jQuery plugin, so the form posts the files to transloadit first. I’d like to create a row for each file uploaded and point it to the location of the file (at s3), but since the “project” parent record hasn’t been created yet, I’m not sure how to set my foreign key.

I assume this is a common use case where a parent/child form needs to be processed on our server as well as post to transloadit. Any best practices on how to set this up so the database records can be inserted properly? I assume this can be done by using the right combination of ‘notify_url’, ‘autoSubmit’, ‘wait’, etc, but I just can’t sort it out yet. Hopefully, I’m explaining the scenario properly.

Thanks for the help.

Hey Carmen,

thanks for getting in touch. From what I understand you need to upload the files first and make sure the jQuery plugin appends them to your form. When you then submit the form, the post requests contains both notes and the files and you can create whatever records are necessary in whichever order.

So what you need is:

  1. wait: true; because you want to wait for all files to be processed first.
  2. autoSubmit: false; because your form should not immediately submit when files are processed. This allows the user to finish whichever notes he is still typing into the text area.
  3. A redirect_url where your form + files is then submitted to.

Please let me know if this helps.

Kind regards,
Tim

I am closing this for now.

Feel free to reopen this ticket if you feel the need to.

Kind regards,
Tim