Actually, I just found solution for my app, again if somebody can provide more portable solution that would be great?
<a href="{{=URL('app/static/image.file',listing.file[11:13], listing.file)}}" rel="prettyPhoto[gallery2]"> <img src="{{=URL('app/static/image.file',listing.file[11:13], listing.file)}}" /> </a> Cheers Ivica On 10 July 2011 00:31, IK <ivicakr...@gmail.com> wrote: > Hi Massimo, > > When "uploadseparate" is set to True, previously mentioned solution > will not work, at least not for me. > > Although, Bruno gave us one suggestion, I would prefer to use explicit > image location rather than image ID. > > To explain: > > ###model: > > db.define_table("image", > ... > > Field('file',"upload",uploadseparate=True,required=True,uploadfolder=request.folder > +'static/' ), > ... > > > ###view > > {{url = URL('static',image.file)}} > {{=A(IMG(_src=url), _href=url)}} > > > This would give invalid file location: > " > <a href="app/static/image.file.9197cf1918d6a0fa. > 6b617374656c61352e6a7067.jpg"><img src="app/static/image.file. > 9197cf1918d6a0fa.6b617374656c61352e6a7067.jpg" /></a> > " > while correct url is > 127.0.0.1/app/static/image.file/91/image.file. > 9197cf1918d6a0fa.6b617374656c61352e6a7067.jpg > > > In attempt to find a solution, I was playing with SUBSTR, but I'm not > getting clean output (I'm not sure if this is good approach, specially > from portability point of view) > > > ###contr > ... > img_folder= db............select(db.image.file [11:13]) > return dict(img_folder=img_folder) > > ###view > {{=img_folder}} > > > > and output is > " > SUBSTR(image.file,12,(14 - 12)) > 91 > " > > If you could give me some pointers, that would be greatly appreciated. > > Thanks > IK > > On Jun 17, 3:18 pm, Massimo Di Pierro <massimo.dipie...@gmail.com> > wrote: > > This is fine: > > > > db.define_table('announce', > > Field('picture','upload',uploadfolder=request.folder+'static/ > > pictures'), > > ) > > > > but why do you need an action to download from the static folder? Why > > not simply use > > > > URL('static',record.picture) > > > > On Jun 17, 5:56 am, Bruno Rocha <rochacbr...@gmail.com> wrote: > > > > > > > > > > > > > > > > > For security reasons, web2py does not expose the 'uploads' folder to > the > > > user, this folder can be accessed only by the 'download' function. > > > > > The best way is to set the upload path pointing to /static not to > /upload > > > and you will have youruploadedfiles to be served as static files, > > > bypassing download function. > > > > > under /static create a folder called 'picture' > > > > > *Go to the table definition and do this:* > > > > > *<model>* > > > db.define_table('announce', > > > > > > Field('picture','upload',uploadfolder=request.folder+'static/pictures'), > > > ) > > > *</model>* > > > > > You are saying DAL to store uploades files in to that folder under > static > > > and store the ath in the field. > > > > > Now in your controller create a function do handle that (different from > > > download, it is a kind of viewer) > > > > > *<controller>* > > > def viewer(): > > > row = db(db.announce.id > > > ==request.args(0)).select(db.announce.picture).first() > > > redirect(URL('static','pictures',args=row.picture)) > > > *</controller>* > > > > > *Now you can fo this:* > > > > >http://server/app/default/viewer/3#record id > > > > > then you got redirected to theimage(no html page) > > > > > example: > http://127.0.0.1:8000/app/static/pictures/announce.picture.aaf5d3f777... > > > > > you can always referdirectlyto theimagepath (not using the viewer > > > function) but you always need to fetch the picture name from db. > > > > > Hope it helps. > > > > > Should go on the book? > > > > > -- > > > Bruno Rocha > > > [ About me:http://zerp.ly/rochacbruno] > > > [ Aprenda a programar:http://CursoDePython.com.br] > > > > > On Thu, Jun 16, 2011 at 6:09 AM, Vinicius Assef <vinicius...@gmail.com > >wrote: > > > > > > Hi guys. > > > > > > I have a table (called anuncio) with an upload field (called foto), > so > > > > anuncio.foto is my upload field. > > > > > > I'm showing andlinkingit with this piece of code in my view : > > > > {{url = URL(c='anuncios',f='download', args=['uploads', > anuncio.foto])}} > > > > {{=A(IMG(_src=url), _href=url)}} > > > > > > My > > > > /contollers/anuncios.py/download()<http://anuncios.py/download%28%29>function > > > > is the default, as seen > > > > below: > > > > def download(): > > > > return response.download(request,db) > > > > > > When user clicks on thisimage, browser shows the download dialog, > > > > asking him/her where to save theimage. > > > > But I'd like to simply show theimage, not present the download > > > > dialog. All these images will be public. > > > > > > How I solved it: > > > > 1) I entered in /myapp/static/images and created a symbolic link > > > > called 'uploads' pointing to /myapp/uploads. > > > > 2) In my view, I changed the: {{url = URL(...}} stuff by this: {{url > = > > > > URL(c='static', f='images', args=['uploads', anuncio.foto])}} > > > > > > I think this isn't the best choice because I'm pointing URL() to a > > > > fake controller and function, and I'm counting on an external > > > > resource: a symbolic link in my filesystem. > > > > > > How would be the "web2pythonic" way to do this? > > > > > > -- > > > > Vinicius Assef. >