Heroku上保存的图像在服务的网页上不可见



我通过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

我的坏。开发树中的文件和文件夹不会映射到web文件夹视图。如果您面临类似的问题,一个好的起点是您的/static文件夹。

最新更新