【发布时间】:2021-01-23 22:25:14
【问题描述】:
我通过 Flask 接收图像并将 response.content 保存到 Heroku 上的 PNG 文件。然后将此图像的名称传递给调用函数,该函数使用提供的 HTML 中的文件名。我在保存文件后验证文件是否存在,离线测试了文件完整性并且一切正常;但是在将它保存在 Heroku 上一秒钟后,它在网页中提供时并不存在。服务器日志如下:
2020-10-08T20:07:00.542480+00:00 app[web.1]: saved fast_graph to disk @ temp/a45329e9-b76b-4714-9e5a-3463b1b6eaf1.png
2020-10-08T20:07:00.542502+00:00 app[web.1]: verified file: temp/a45329e9-b76b-4714-9e5a-3463b1b6eaf1.png
2020-10-08T20:07:01.934587+00:00 app[web.1]: 10.13.251.139 - - [08/Oct/2020:20:07:01 +0000] "GET /temp/a45329e9-b76b-4714-9e5a-3463b1b6eaf1.png HTTP/1.1" 404 232 "http://XXX.herokuapp.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0"
2020-10-08T20:07:01.937442+00:00 heroku[router]: at=info method=GET path="/temp/a45329e9-b76b-4714-9e5a-3463b1b6eaf1.png" host=XXX.herokuapp.com request_id=37f77e3b-35ce-4355-b5ca-84b84a51718b fwd="X.X.191.107" dyno=web.1 connect=1ms service=4ms status=404 bytes=400 protocol=http
这是 Heroku 临时文件系统的属性还是我做错了什么?我的代码如下:
# get file path of generated chart
response = requests.get(
if90_clientbase + f"?client_id={client_id}&action={api_action}")
# check the outcome
outcome = response.json().get("outcome")
if not outcome:
return False
# get the filename and fetch the file
file_name = response.json().get("value")
response = requests.get (if90_filesbase + f"?file_name={file_name}")
# generate filename, save fetched content
save_file = f"{temp_folder}{lib_misc.unique_filename()}.png"
with open(save_file, 'wb') as f:
f.write(response.content)
return save_file
【问题讨论】: