【发布时间】:2017-06-23 09:53:37
【问题描述】:
我需要将图像文件上传到某个文件夹。它在 localhost 上运行良好,但如果我将应用程序推送到 heroku,它会告诉我:
IOError: [Errno 2] No such file or directory: 'static/userimg/1-bild-1.jpg'
这说明找不到文件夹?
我需要将图像文件存储几秒钟以对主题执行一些操作。之后,它们将被发送到 AWS 并从文件夹中删除。
这就是我将图像保存到文件夹中的代码:
i = 1
for key, file in request.files.iteritems():
if file:
filename = secure_filename(str(current_user.id) + "-bild-"+ str(i) +".jpg")
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
i = i + 1
后来我从这样的文件夹中获取文件:
for item in os.listdir(os.path.join(app.config['UPLOAD_FOLDER'])):
if item.startswith(str(current_user.id)) and item.split(".")[0].endswith("1"):
with open(os.path.join(app.config['UPLOAD_FOLDER'], item), "rb") as thefile:
data = base64.b64encode(thefile.read())
upload_image_to_aws_from_image_v3('MYBUCKET', "userimg/", data, new_zimmer, "hauptbild", new_zimmer.stadt, new_zimmer.id)
os.remove(str(thefile.name))
即app config中的上传文件夹:
UPLOAD_FOLDER = "static/userimg/"
在本地主机上一切正常。
【问题讨论】: