`Currently, I'm using "send_from_directory" to serve the tar.gz file. It's working good for 200-300 Mb file but if file size more than 300 Mb or 400 Mb it's giving and issue.
`@app.route('/download', methods=['GET','POST'])
def download():
json_data = request.get_json()
print(json_data)
data = mongo.db.data
if 'file_name' in json_data:
try:
file_name = json_data['file_name']
pathdir = json_data['pathdir']
zipfile = pathdir+'/'+str(file_name)+'.tar.gz'
if os.path.exists(zipfile):
os.remove(zipfile)
tar = tarfile.TarFile.gzopen(zipfile, mode="w")
tar.add(pathdir, arcname=os.path.basename(pathdir))
tar.close()
return send_from_directory(pathdir, str(file_name)+'.tar.gz', as_attachment=True)
except Exception as e:
logger.exception("Exception occurred in code.")
return jsonify(error='file_name not found'+str(e))
else:
return jsonify(message='please provide file_name name.')`
.tar.gz
file on the system if not prevented by the OS. flask.send_file
function. This function will accept a file pointer, so you can open the file you want to send and then pass the file handle of the open file to this function. In this way, the entire file should never have to be held in memory.