Search code examples
pythonherokufastapi

Download image on heroku


i have a simple function in fastapi python

url="some_random_video_url_here"
re = requests.get(url)
with open("download/hello.png", 'wb') as file: #save hello.png to download folder
    file.write(re.content)
    file.close()

this function work locally fine and download image and any files bot when upload on heroku not download image and save in staticsFiles folder

please help


Solution

  • Heroku's filesystem is ephemeral/short lived. This means that any images you save locally will disappear after you redeploy your app. You can't rely on Heroku's filesystem to store images that need to persist for a longer time.

    For saving images, have a look at 3rd party storage solutions such as Cloudinary or AWS S3.