Designing File Upload / Parsing / Third Party Structure

I need to:

  1. Upload a csv or pipe-delimited file
  2. Parse the file for specific attributes and save it in a database
  3. Generate a query to a third party based on the parsed information
  4. Receive a response from third party
  5. Save the response info into DB
  6. View the response Data.

For the first 3 steps, I’m trying to figure out the best way to parse and generate the query. Should I save the file to the DB and then parse it?
Should I parse in the controller before the file is saved in the db?
Should I use the information saved in temporary values to create a third-party query?
Is there a gem that can handle all of this?

Any advice would be greatly appreciated.