Reputation: 435
I am trying to make an SQLFORM that does a default upload if the the user does not put anything in the upload section. I have the file(a .png image) saved in my static/images directory. If the user actually submits a file it gets properly but my default doesn't work. For making the default I am trying
form.vars.image_thumbnail = db.myTable.image_thumbnail.store(open(os.path.join(request.folder, 'static', 'images','defaultUpload.png'),'rb')))
which is like what I do in other cases that I want this default image in the table. Is there a good way to do this.
Ok simple explanation: I have a table with an upload field. I want to put an SQLFORM on a page to insert a new entry. I also want that form to recognize when the user has left the upload section blank and fill it in with a file that is in the static folder. Can I do this with an SQLFORM?
Upvotes: 2
Views: 591
Reputation: 19290
For the sake of completeness, if you also want your default content be dynamically generated, you can use manual upload (which actually means "programmable upload").
stream = open(filename, 'rb')
db.myfile.insert(image=db.myfile.image.store(stream, filename))
Upvotes: 0
Reputation: 61
This should work:
import os
db.myTable.image_thumbnail.default = os.path.join(request.folder, 'static', 'images', 'defaultUpload.png')
If the user doesn't upload a file, it will store a copy of default file. It handles updates too: if the user deletes existing file, it will store a copy of default file.
Upvotes: 2