0

Using Vue/Electron to post to rails/Postgres backend.

Is there a common design pattern/approach to posting multiple audio file objects BUT in a single post request?

My current process (which works, but is very slow) is to convert each audio file's binary data to text, append it to my JSON and then send it all to the server at once and then reverse the process on the other side.

The data has a parent audio file that has N number of related child audio files and each audio file has associated data collected from the user. It would not be unusual to have 20 files to send at one time.

My goal was to limit the number of API calls and the risk that some files might post successfully but others would not, and then Id end up with an incomplete transaction.

Any ideas from experienced engineers on how they might approach this problem would be appreciated.

5
  • 1
    So basically you want to post a form with multiple files? Have you tried multipart/form-data?
    – Rik D
    Nov 11, 2020 at 11:50
  • Basically. But, I'm not using an HTML form or a file input control. Scanning the user's file system (Electron/Desktop) for a match on some criteria, converting matched files to text, and using formData() to post to rails. I don't know how to put the file objects into a formData() post without using an HTML file input, but if it can be done, then this in combination with multipart/form-data should be a win. I'll do some digging. Thanks. Nov 11, 2020 at 19:14
  • Have you tried this?
    – Blake
    Nov 13, 2020 at 15:52
  • @Blake No, I hadn't come across that SO post in my searching but this looks like it will work for me. Many thanks. Nov 15, 2020 at 16:21
  • here is another solution:stackoverflow.com/questions/60187372/…
    – Ishan Shah
    Nov 17, 2020 at 5:06

1 Answer 1

0

Don't post the files all at once.

Allow the user to upload the files to a temp file on the server. That should be a separate POST. It should respond with a temporary file name that you save in your form.

Upon posting back the main form move the temp files into their permanent storage and delete the temp files.

You'll need a scheduled job to clean up temp files that got abandoned.

You can build in the ability to upload multiple files at once, thereby reducing the time it takes to upload them (restricted on the user's upload speed).

Processing the main form takes less time as well because the files already reside in the server.

1
  • Thanks Greg. I was able to get a working solution that generally follows the flow you suggested. With help from here and @Blakes suggestion. Dec 30, 2020 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.