What datatype should I use for image in my flask sqlite database? What datatype should I use for image in my flask sqlite database? sqlite sqlite

What datatype should I use for image in my flask sqlite database?


parser.add_argument(’picture’, type=werkzeug.datastructures.FileStorage, location=’files’)


Normally images like this also need to be uploaded from a browser in addition to being served back out.

For that reason I use Flask-Uploads which handles all of the storage and naming issues for you when uploaded and when served.

Here's an example from the docs of how to use it:

photos = UploadSet('photos', IMAGES)@app.route('/upload', methods=['GET', 'POST'])def upload():    if request.method == 'POST' and 'photo' in request.files:        filename = photos.save(request.files['photo'])        rec = Photo(filename=filename, user=g.user.id)        rec.store()        flash("Photo saved.")        return redirect(url_for('show', id=rec.id))    return render_template('upload.html')@app.route('/photo/<id>')def show(id):    photo = Photo.load(id)    if photo is None:        abort(404)    url = photos.url(photo.filename)    return render_template('show.html', url=url, photo=photo)

You use the .save() method to store the incoming file in a directory. Flask-Uploads returns to you the filename it was saved with. Later, you use .url() or .path() to get a reference to the saved file.