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

flask, python, sqlite

Solution

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

Problem

So I have this db.model in my sqlite database in Flask. It looks like this: ``` class Drink(db.Model): id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(64), index = True) kind = db.Column(db.String(64), index = True) image = db.Column(db.LargeBinary) def __init__(self, name, kind, image): self.name = name self.kind = kind self.image = image def __repr__(self): return '<Drink %r>' % self.name ``` So, this issue is that I have this column, image, which will be an actual picture, but I don't know what datatype to use in the flask code. Here is the flask code: Flask ``` class DrinkAPI(Resource): def __init__(self): self.reqparse = reqparse.RequestParser() self.reqparse.add_argument('name', type = str, required = True, help = 'No name title provided', location = 'json') self.reqparse.add_argument('type', type = str, required = True, help='No type provided', location = 'json') self.reqparse.add_argument('image', type = blob, required = True, help='No image provided', location = 'json') super(DrinkAPI, self).__init__() def get(self, id): if checkDrink(id): info = getDrinkInfo(id) return {'id': id, 'name': info[0], 'type':info[1], 'image': info[2]} abort(404) def put(self, id): if checkDrink(id): args = self.reqparse.parse_args() deleteDrink(id) drink = Drink(args['name'], args['type'], args['image']) addDrink(drink) return {'drink' : marshal(drink, drink_fields)}, 201 abort(404) def delete(self, id): deleteDrink(id) return { 'result': True} ``` See where I set the type of my `reqparse` of `image` to `blob`? That's not even an actual datatype, but I don't know what to put there. Do I need to subclass the `fields.Raw`? Any ideas? Thanks NEW APPROACH TO QUESTION Based on some comments, it seems like I should be storing the image in my static folder. I can do that. But then how do I reference it with my database? Is it a string that corresponds to the `.jpg` file?

Original source

Related problems