Ajeet Singh
Ajeet Singh

Reputation: 91

How to pass a CSV file to a Flask app running inside a Docker container?

I have a Flask app running inside Docker container. My app takes the path of a CSV file as input, processes it, and gives some results.

While creating the container I stored a CSV file inside the container itself to test the code. And now when everything is working fine I have to pass this CSV file from outside.

This is because for every API call there will be different CSV file.

Please note that the CSV file will be passed by end-user so it can't be anywhere on the system when we start the container. It will be received after running the container.

How can I provide this CSV file to my application?

Upvotes: 0

Views: 458

Answers (1)

Chris
Chris

Reputation: 136968

My app takes the path of a CSV file as input

It shouldn't take a path to a file. Your users won't have access to the server's filesystem, and your server doesn't have access to your clients' filesystem.

Instead, it should take a file payload in an HTTP request:

  1. A <form> tag is marked with enctype=multipart/form-data and an <input type=file> is placed in that form
  2. The application accesses the file from the files dictionary on the request object.
  3. use the save() method of the file to save the file permanently somewhere on the filesystem.

Upvotes: 4

Related Questions