当配置上传目录是
UPLOAD_FOLDER = '/app/uploads'
执行
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
没报错
再执行
@app.route('/uploads/')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'],
filename)
在浏览器上面可以看到图片,但是找不到上传的目录
当配置上传目录是
UPLOAD_FOLDER = 'app/uploads'
执行
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
没报错
再执行
@app.route('/uploads/')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'],
filename)
在浏览器上面开不到图片,但是找到上传目录
关键在于 上传目录的'/'
怎样才能上传了之后在浏览器看到图片,也找到对应的上传目录呢
Under normal circumstances, the first way of writing is recommended, and there is no discussion about whether the second way of writing is right or wrong.
Maybe your system is Windows, and your upload path is written in Linux, which will cause
os.path.join
exception:For example:
/app/uploads
and1.txt
combined:/app/uploads/1.txt
/app/uploads.txt