Menu Close

How to read file data without saving it in Python Flask?

Sometimes, we want to read file data without saving it in Python Flask.

In this article, we’ll look at how to read file data without saving it in Python Flask.

How to read file data without saving it in Python Flask?

To read file data without saving it in Python Flask, we can access the file from request.files.

For instance, we write

@app.route('/upload/', methods=['POST'])
def upload():
    if request.method == 'POST':
        file = request.files["file"]                    
        if file:
            df = pd.read_excel(files_excel["file"])

to get the file with request.files["file"]

Then we can do what we want with the file without saving it.

Conclusion

To read file data without saving it in Python Flask, we can access the file from request.files.

Posted in Python, Python Answers