'Posgres Not storing images
This is a screenshotAnybody know what may be causing this? I am building a Flask app and deployed on Heroku. I then uploaded posts to test the blog app and everything seemed to be fine but after some time the images were all gone. So, I am guessing my images are not being stored in my database?
This is my post upload Python Code:
@views.route('/addpost', methods=['POST', 'GET'])
@login_required
def addpost():
if request.method =="POST":
title = request.form.get('title')
body = request.form.get('content')
photo = save_images(request.files.get('photo'))
post= Post(title=title, body=body, image=photo, author =current_user)
db.session.add(post)
db.session.commit()
flash("Your post has been submitted", 'success')
return redirect('dashboard')
return render_template ('admin/addpost.html')
Solution 1:[1]
All heroku dynos are restarted every 24 hours in a process called cycling. Any changes to the local filesystem will be deleted, so your images are not being stored locally. You can read more about this on heroku's devcenter
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | wikwoj |
