I have created a Flask app that receives XML file, processes it, saves it on my machine and sends that copy of .xlsx file as response.
The problem is whenever I am sending the .xlsx file, the requester gets the .xlsx file in unreadable format. Also, the file at my machine that is saved is 6kb while the requester receives 9kb file. I did the same with .CSV format and it works fine.
I am using Apache v2.4 and mod_wsgi v5.0 Python v3.12.1.
Following is my code:
import request
from flask import Flask, send_file, redirect
@app.route('/func0')
def func0():
# Store XML in a directory
return redirect_to_func1
@app.route('/func1', methods=['POST'])
def funct1():
#.. Some processing
resp = send_file(os.path.join(path_to_file, filename), mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', as_attachment=True)
return resp
I looked through everywhere tried all combinations. The thing is it worked with .CSV file while it not working with .xlsx file.