Re: [web2py] Re: Linking directly to an uploaded image

2011-07-11 Thread pbreit
I was thinking that if download works then you could look at the download code 
to see how it does it.


Re: [web2py] Re: Linking directly to an uploaded image

2011-07-11 Thread Ivica Kralj
Hi

Pbreit,

It does, but if you are trying to open an image in browser using download()
function with A tag ( wrote:

> Does the download() function handle the file paths properly?
>
> def download():
> """
> allows downloading of uploaded files
> http:///[app]/default/download/[filename]
> """
> return response.download(request,db)
>
>


Re: [web2py] Re: Linking directly to an uploaded image

2011-07-10 Thread pbreit
Does the download() function handle the file paths properly?

def download():
"""
allows downloading of uploaded files
http:///[app]/default/download/[filename]
"""
return response.download(request,db)



Re: [web2py] Re: Linking directly to an uploaded image

2011-07-10 Thread Ivica Kralj
Actually,

I just found solution for my app, again if somebody can provide more
portable solution that would be great?



   


Cheers
Ivica


On 10 July 2011 00:31, IK  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:
> "
>
> "
> 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= dbselect(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 
> 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  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:*
> >
> > > **
> > > db.define_table('announce',
> >
> > >
> Field('picture','upload',uploadfolder=request.folder+'static/pictures'),
> > > )
> > > **
> >
> > > 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)
> >
> > > **
> > > def viewer():
> > > row = db(db.announce.id
> > > ==request.args(0)).select(db.announce.picture).first()
> > > redirect(URL('static','pictures',args=row.picture))
> > > **
> >
> > > *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  >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()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.
>


Re: [web2py] Re: Linking directly to an uploaded image

2011-06-17 Thread Vinicius Assef
Thank you all.

Certainly it will go to the book, Bruno. ;-)

--
Vinicius Assef.


On Fri, Jun 17, 2011 at 12:19 PM, Bruno Rocha  wrote:
> The viewer action is only for cosmetics, to work as an URL shortener. The
> filename generated by DAl is so extense.
> BTW: I mentioned in the end of the email:
> "you can always refer directly to the image path (not using the viewer
> function) but you always need to fetch the picture name from db"
> On Fri, Jun 17, 2011 at 11:19 AM, Massimo Di Pierro
>  wrote:
>>
>> I think that is the point. In 'uploads' if you need authorization. In
>> 'static' if you do not. In the latter you do not need to worry about
>> authorization and you can let the web server by-pass web2py (so do not
>> viewer action).
>>
>> On Jun 17, 9:16 am, Anthony  wrote:
>> > Thanks, Bruno -- this is very helpful. With this method, you can't
>> > enforce
>> > authorization, though, right? So this should only be used for uploaded
>> > files
>> > intended to be accessed by anyone.
>> >
>> > Anthony
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Friday, June 17, 2011 6:56:52 AM UTC-4, rochacbruno 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 your uploaded files to be served as static files,
>> > > bypassing download function.
>> >
>> > > under /static create a folder called 'picture'
>> >
>> > > *Go to the table definition and do this:*
>> >
>> > > **
>> > > db.define_table('announce',
>> >
>> > >
>> > > Field('picture','upload',uploadfolder=request.folder+'static/pictures'),
>> > >                         )
>> > > **
>> >
>> > > 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)
>> >
>> > > **
>> > > def viewer():
>> > >     row = db(db.announce.id
>> > > ==request.args(0)).select(db.announce.picture).first()
>> > >     redirect(URL('static','pictures',args=row.picture))
>> > > **
>> >
>> > > *Now you can fo this:*
>> >
>> > >http://server/app/default/viewer/3# record id
>> >
>> > > then you got redirected to the image (no html page)
>> >
>> > > example:
>> >
>> >
>> > > >http://127.0.0.1:8000/app/static/pictures/announce.picture.aaf5d3f777...
>> >
>> > > you can always refer directly to the image path (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
>> > > 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 and linking it 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() function is the default, as
>> > >> seen
>> > >> below:
>> > >> def download():
>> > >>    return response.download(request,db)
>> >
>> > >> When user clicks on this image, browser shows the download dialog,
>> > >> asking him/her where to save the image.
>> > >> But I'd like to simply show the image, 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.
>


Re: [web2py] Re: Linking directly to an uploaded image

2011-06-17 Thread Bruno Rocha
The viewer action is only for cosmetics, to work as an URL shortener. The
filename generated by DAl is so extense.

BTW: I mentioned in the end of the email:

"you can always refer directly to the image path (not using the viewer
function) but you always need to fetch the picture name from db"

On Fri, Jun 17, 2011 at 11:19 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> I think that is the point. In 'uploads' if you need authorization. In
> 'static' if you do not. In the latter you do not need to worry about
> authorization and you can let the web server by-pass web2py (so do not
> viewer action).
>
> On Jun 17, 9:16 am, Anthony  wrote:
> > Thanks, Bruno -- this is very helpful. With this method, you can't
> enforce
> > authorization, though, right? So this should only be used for uploaded
> files
> > intended to be accessed by anyone.
> >
> > Anthony
> >
> >
> >
> >
> >
> >
> >
> > On Friday, June 17, 2011 6:56:52 AM UTC-4, rochacbruno 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 your uploaded files to be served as static files,
> > > bypassing download function.
> >
> > > under /static create a folder called 'picture'
> >
> > > *Go to the table definition and do this:*
> >
> > > **
> > > db.define_table('announce',
> >
> > >
> Field('picture','upload',uploadfolder=request.folder+'static/pictures'),
> > > )
> > > **
> >
> > > 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)
> >
> > > **
> > > def viewer():
> > > row = db(db.announce.id
> > > ==request.args(0)).select(db.announce.picture).first()
> > > redirect(URL('static','pictures',args=row.picture))
> > > **
> >
> > > *Now you can fo this:*
> >
> > >http://server/app/default/viewer/3# record id
> >
> > > then you got redirected to the image (no html page)
> >
> > > example:
> >
> > >http://127.0.0.1:8000/app/static/pictures/announce.picture.aaf5d3f777.
> ..
> >
> > > you can always refer directly to the image path (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  >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 and linking it 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() function is the default, as
> seen
> > >> below:
> > >> def download():
> > >>return response.download(request,db)
> >
> > >> When user clicks on this image, browser shows the download dialog,
> > >> asking him/her where to save the image.
> > >> But I'd like to simply show the image, 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.
>