Flask Uploads Photo class

553 Views Asked by At

Trying to write a website that will allow users to upload photos, and so far, I've been using the Flask-Uploads library (docs here)

Used in the example in the docs is a class Photo that seems fairly critical:

    rec = Photo(filename=filename, user=g.user.id)
    rec.store()
    ...
    photo = Photo.load(id)

Problem being that the name Photo doesn't exist in flask.ext.uploads and I'm not sure where to upload it from.

Has anyone else experienced the same issue?

1

There are 1 best solutions below

0
On

Photo is a model class that you'd need to define. If you take a look at the example application you'll see a class named Post.

post = Post(title=title, caption=caption, filename=filename)
post.id = unique_id()
post.store()

This particular example was made using Flask-CouchDB, but you can use any data store you'd like. You'll just need to replace the lines that save the Photo or Post with however you save references to uploaded files in your application.