Hello, I created a website that modified the image with Pillow and then downloaded it. Locally these two codes work perfectly but with pythonanywhere the image is not downloaded. I need help. Here are the two possible codes :
flask_app.py
from flask import Flask, request, redirect, url_for, render_template, send_file
from werkzeug import secure_filename
from PIL import Image
import os
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def upload():
return render_template('upload.html')
@app.route('/download/', methods=['POST'])
def download():
try:
image = request.files['image']
nom_image = secure_filename(image.filename)
image = Image.open(image)
...
image.save('/home/modificateurimage/mysite/static/images/'+nom_image)
return send_file('/home/modificateurimage/mysite/static/images/'+nom_image, mimetype='image/jpeg', attachment_filename=nom_image, as_attachment=True), os.remove('/home/modificateurimage/mysite/static/images/'+nom_image)
except Exception as e:
print(e)
return redirect(url_for('upload'))
OR flask_app.py
from flask import Flask, request, redirect, url_for, render_template, send_file
from werkzeug import secure_filename
from PIL import Image
from io import BytesIO
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def upload():
return render_template('upload.html')
@app.route('/download/', methods=['POST'])
def download():
try:
image = request.files['image']
nom_image = secure_filename(image.filename)
image = Image.open(image)
...
img_io = BytesIO()
image.save(img_io, extension.upper(), quality=70)
img_io.seek(0)
return send_file(img_io, mimetype='image/jpeg', attachment_filename=nom_image ,as_attachment=True)
except Exception as e:
print(e)
return redirect(url_for('upload'))