我写了一个应用https://images99acres.herokuapp.com/。
此应用程序允许用户上传图像,如果我在本地运行此应用程序,则此应用程序将上传图像并将其保存到我指定的路径中,
但是我在Heroku上上传了此应用,当有人上传图片时,它在https://images99acres.herokuapp.com/_uploads/photos/activate%20virtual_environment.jpg上上传了图片
“ _ uploads / photos / image.jpg”
下面是我的代码:
from flask import Flask, redirect, render_template, request, session, url_for
from flask_dropzone import Dropzone
from flask_uploads import UploadSet, configure_uploads, IMAGES, patch_request_class
import os
app = Flask(__name__)
dropzone = Dropzone(app)
app.config['SECRET_KEY'] = 'supersecretkeygoeshere'
# Dropzone settings
app.config['DROPZONE_UPLOAD_MULTIPLE'] = True
app.config['DROPZONE_ALLOWED_FILE_CUSTOM'] = True
app.config['DROPZONE_ALLOWED_FILE_TYPE'] = 'image/*'
app.config['DROPZONE_REDIRECT_VIEW'] = 'results'
# Uploads settings
app.config['UPLOADED_PHOTOS_DEST'] = os.getcwd() + '/uploads'
photos = UploadSet('photos', IMAGES)
configure_uploads(app, photos)
patch_request_class(app) # set maximum file size, default is 16MB
@app.route('/', methods=['GET', 'POST'])
def index():
# set session for image results
if "file_urls" not in session:
session['file_urls'] = []
# list to hold our uploaded image urls
file_urls = session['file_urls']
# handle image upload from Dropszone
if request.method == 'POST':
file_obj = request.files
for f in file_obj:
file = request.files.get(f)
# save the file with to our photos folder
filename = photos.save(
file,
name=file.filename
)
# append image urls
file_urls.append(photos.url(filename))
session['file_urls'] = file_urls
return "uploading..."
# return dropzone template on GET request
return render_template('index.html')
@app.route('/results')
def results():
# redirect to home if no images to display
if "file_urls" not in session or session['file_urls'] == []:
return redirect(url_for('index'))
# set the file_urls and remove the session variable
file_urls = session['file_urls']
session.pop('file_urls', None)
return render_template('results.html', file_urls=file_urls)
if __name__=="__main__":
app.run()
#app.run(debug=True)
我该怎么办?我该如何解决?