Displaying images

100 views
Skip to first unread message

Dave S

unread,
Apr 5, 2017, 3:44:47 AM4/5/17
to web2py-users
I have a bunch of pix that I want to display, which are not in the uploads directory of the application.  My options appear to be:

- copy them to the static folder (or a subfolder) and have URL() work for them
- set up streamio on each so I can read them from an arbitrary filesystem location
- store them as a blob in the database

Is there another option?

If there was just a handful, relatively stable over time, the static option would seem a good idea (because it would be simple to do).  But I took more than 20 shots yesterday (starting with spring hillsides, and then trying to capture birds in flight), and that was just one outing (limited by the memory card). Taking down those pictures before putting up the next set also seems "un-static".

The blob option might be good, but not until I set up a real DB engine (I'm not a DB admin) or use mlabs.  Meanwhile, I'm still on sqlite.

Also, I might want to look into how to cache the images (not because there will be heavy use, but because this might be a good application to use for the learning experience).

Suggestions?

/dps

Massimo Di Pierro

unread,
Apr 12, 2017, 7:31:42 AM4/12/17
to web2py-users
I would do:

def custom_download():
     filename = request.args(0)
     # maybe validate filename
     full_path = os.path.join('/whereever/it/is', filename)
     return response.stream(full_path)

and call with http://..../custom_download/yourfilename

Dave S

unread,
Apr 13, 2017, 4:35:14 AM4/13/17
to web2py-users


On Wednesday, April 12, 2017 at 4:31:42 AM UTC-7, Massimo Di Pierro wrote:
I would do:

def custom_download():
     filename = request.args(0)
     # maybe validate filename
     full_path = os.path.join('/whereever/it/is', filename)
     return response.stream(full_path)

and call with http://..../custom_download/yourfilename


Thanks!  That works nicely.

Dave
/dps
 

Dave S

unread,
Apr 13, 2017, 4:37:39 AM4/13/17
to web2py-users
By the way,  is there an easy way of installing pillow for the Windows web2py, where python is a dll?

/dps

Dave S

unread,
Apr 27, 2017, 5:50:10 AM4/27/17
to web2py-users
On Wednesday, April 12, 2017 at 4:31:42 AM UTC-7, Massimo Di Pierro wrote:
I would do:

def custom_download():
     filename = request.args(0)
     # maybe validate filename
     full_path = os.path.join('/whereever/it/is', filename)
     return response.stream(full_path)

and call with http://..../custom_download/yourfilename


I'd like to extend this to displaying several images, akin to having a page of <IMG>'s ... say a thumbnail page display.  If I try returning a list of response.stream thingies, only the first gets shown.  Do I need to make a list of LOAD helpers, each of which streams 1 image?

/dps

Matt Bockman

unread,
May 7, 2017, 2:16:32 PM5/7/17
to web2py-users
How big is your application/user base? Is sqlite not sufficient? I unwittingly thought sqlite was kind of a toy until I did a little more research to find out that it is actually very capable and used in a lot of applications. Based on this:


Seems like pretty much any application I see myself writing will work well in sqlite. 

That being said, the web2py upload field type seems to be very useful, as it automagically renames the file and stores it into the upload folder, and stores the path to that file in the database. Also, by some more magic, when you download the file, it retains the original file name. Pretty neat. Read more here:


Cheers,
Matt 

Dave S

unread,
May 9, 2017, 1:28:39 AM5/9/17
to web2py-users
On Sunday, May 7, 2017 at 11:16:32 AM UTC-7, Matt Bockman wrote:
How big is your application/user base?

At the moment, 1.
 
Is sqlite not sufficient?

sqlite works quite well for me.  But there are applications where it won't scale, mainly because of the locking mechanism.  I would rather not be under the pressure of a deadline when I learn some of the Grownup App techniques.
 
I unwittingly thought sqlite was kind of a toy until I did a little more research to find out that it is actually very capable and used in a lot of applications. Based on this:


Seems like pretty much any application I see myself writing will work well in sqlite. 

That being said, the web2py upload field type seems to be very useful, as it automagically renames the file and stores it into the upload folder, and stores the path to that file in the database. Also, by some more magic, when you download the file, it retains the original file name. Pretty neat. Read more here:



I use that feature in several apps.  This one is different in that I am NOT uploading files; they have their own life on the file system, and I can be adding a couple hundred at a time.

 
Cheers,
Matt 


Cheerio!

Dave
/dps
Reply all
Reply to author
Forward
0 new messages