Given this model:
db.define_table('pics',Field('image','upload'))
And this controller:
def index():
form = SQLFORM(db.pics)
if form.accepts(request.vars,session):
response.flash = form.vars.image
return dict(form=form)
The file name of the uploaded file will be in form.vars.image if the
form is accepted. There is a download action in your controller by
default that you can use to download the file:
def download():
"""
allows downloading of uploaded files
http://..../[app]/default/download/[filename]
"""
return response.download(request,db)
You can generate a url from this action:
URL('download', args=form.vars.image)
On Nov 7, 4:11 pm, Luther Goh Lu Feng <[email protected]> wrote:
> I have a simple table that holds uploaded images
>
> ========================
> db.define_table('image',
> Field('image', 'upload', notnull=True),
> )
>
> ========================
>
> I would like to obtain the download url for uploaded images. How can I
> obtain that in the action, and then render it in the view using
> {{=URL}}?
>
> ========================
> image_upload_form = crud.create(db.image)
> if image_upload_form.accepts(request.vars,session):
> response.flash = 'Image uploaded'
> elif image_upload_form.errors:
> response.flash = 'Image form has errors'
> ========================