我正在尝试访问上传到 Heroku 临时文件存储系统的文件。(我知道这些文件仅适用于特定的 dyno)文档说 /tmp 目录是上传到的位置。
我相信我的重定向网址端点不正确:
.py
UPLOAD_FOLDER_FACES = '/app/tmp/'
app.config['UPLOAD_FOLDER_FACES'] = UPLOAD_FOLDER_FACES
@app.route("/AddFace", methods=["GET", "POST"])
def add_face():
if 'image' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['image']
if file.filename == '':
flash('No image selected for uploading')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER_FACES'], filename))
flash('Face successfully uploaded, saved and displayed')
return render_template('addface.html', filename=filename)
else:
flash('Allowed image types are -> png, jpg, jpeg, gif')
return redirect(request.url)
return render_template("addface.html")
@app.route('/displayfaces/<filename>')
def display_image_face(filename):
# print('display_image filename: ' + filename)
return redirect(url_for('app', filename='tmp/' + filename), code=301) <-----error
超文本标记语言
{% if filename %}
<div>
<img src="{{ url_for('display_image_face', filename=filename) }}">
</div>
{% endif %}
我使用 bash 探索了 heroku 上的文件结构:
C:\Flask\app>heroku run bash --app faces-application
Running bash on ⬢ faces-application... up, run.3918 (Free)
~ $ ls
Aptfile forms.py gui.py Procfile requirements.txt runtime.txt static templates
~ $ pwd
/app
~ $ cd ..
/ $ ls
app bin dev etc lib lib64 lost+found proc sbin sys tmp usr var
/ $ pwd
/
/ $ cd var
/var $ ls
lib log tmp
/var $ pwd
/var
这也没有取得成功的结果。
Heroku 上传与哪个 /tmp 关联? 我想知道我是否需要在 /app/ 中创建一个 tmp 目录,因为 Heroku 没有创建它?或者 Heroku 使用 '/' tmp 目录还是 /var/ tmp 目录?
慕容森
相关分类