J
J
Jekson2019-03-14 15:31:22
Flask
Jekson, 2019-03-14 15:31:22

How to upload images to database in flask?

I am using SQLAlchemy. I can’t figure it out, for example, in django, the corresponding field indicates the folder to save

img = models.ImageField(upload_to=user_directory_path, verbose_name='Ваше фото')

How to do it in flask?
I have this model:
class Image(db.Model):
    __tablename__ = 'images'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String())
    img_filename = db.Column(db.String())
    img_count = db.Column(db.Integer)
    creation_date = db.Column(db.TIMESTAMP, server_default=db.func.current_timestamp(), nullable=False)

    def __repr__(self):
        return '<image id={},name={}>'.format(self.id, self.name)

but I don't see anything related to images in the list of fields in SqlAlchemy.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-03-16
@skipirich

look at this module https://github.com/rstit/flask-image-alchemy I haven't tried it myself, but it looks like it's just what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question