Im trying to upload an image to a folder on the system and give it a unique identifier. That way each member can have there own profile image. Im having trouble assigning an id and not sure if im going about this correctly. Also, Would it be better to put the image in the SQLalchemy database or just a folder?
@main.route("/upload", methods=['GET', 'POST'])
@login_required
def upload():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
rec = file(filename=filename, user=g.user.id)
rec.store()
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('.home'))
return """
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
<p>%s</p>
""" % "<br>".join(os.listdir(app.config['UPLOAD_FOLDER'],))
my error: File "/home/ed/Development/Python/social/app/main/views.py", line 253, in upload rec = file(filename=filename, user=g.user.id) TypeError: 'FileStorage' object is not callable