Answer the question
In order to leave comments, you need to log in
How to add receiving a large binary file to the application API developed on Flask?
Hello to all!
UPD : Reworded my question.
I have a task related to the development of an API feature for my Flask REST application, which I still cannot figure out how to solve it.
More details:
1. An application is written in Flask
2. It is written to work with large binary files (up to 50 MB)
3. The load on the application is no more than 3-4 client applications within 10 minutes
4. Interaction with the application only through the API
Need to:
Teach my application accept large binary files, up to 50 MB. In other words, I need the client application to be able to send a binary HTTP POST request to a URI like " https://myservice.com/executable/ "". In response, the client application will receive JSON, which will indicate the ID of the file sent.
NB : One must take into account the fact that several clients can access the application and none of the clients should wait in line.
I have no understanding of solving problems:
1. How to get around the fact that Flask is blocking and synchronous, but still use Flask, even if in conjunction with another Framework that decides what Flask can't
2. How to transfer large binaries
Yesterday Gen1us2k suggested using Twisted and Redis. Since I am a beginner, I would like to know other opinions as well.
Answer the question
In order to leave comments, you need to log in
Helped advice, answers and personal advice Alexey and @Gen1us2k.
End result:
Server side, i.e. my application is
something like this:
app.config['UPLOAD_DIR'] = config.UPLOAD_DIR
@app.route('/uploads', methods='POST')
def upload_file():
file = request.files['file']
filename = secure_filename(file.filename)
file.save(os.path(app.config['UPLOAD_DIR'],filename))
For the task above, a flask is enough. And if you do some long operation with the file, then twisted is better.
If you are absolutely sure that you will not have more than 4 clients at the same time, then run your Flask application in 4+n processes and that's it (n additional processes are needed if someone sends some other requests besides downloading the file). If the probability of an influx of more than 4 clients at the same time is different from 0, then put something asynchronous next to it (twisted, tornado, etc.) and process file uploads there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question