Update, as a test, I  pulled one banner image like this

def pullimage():
    row=db(db.myimages.id==100).select().first()
    filen=open(os.path.join(request.folder,'static',row.banner),'a')
    filen.write(row.banner_image)
    filen.close()
    return

This seems to have stored the image just fine. I guess I could run a loop 
to pull all images, no problem.
I would still appreciate expert guidance though...
a) Is it better to hold images in the file system or in the database? 
(given a potential 1000s)
b) If I change the table definition to be "uploadfolder", will this work 
OK, or is there a subtlety that will break something  (i.e. where I am 
using the image in the app)
    I am really unsure about the impact of changing the db.define_table in 
db.py

Simon
------------

On Wednesday, May 21, 2014 10:42:07 PM UTC+1, SimonD wrote:
>
> I see in this forum that some folk have wanted to migrate "uploads stored 
> in the file system" to "uploads stored in the database".
> Massimo has shown a simple piece of code to assist that migration.
>
> I think I have the opposite requirement.
>
> Firstly....
> I had assumed that storing uploads in the file system would be preferred? 
> (with uploadseparate=True)
> I would like to ask if, in fact, it is really better to hold them in the 
> database rather than the file system?
> Is there (or is there not) an impact on the database of holding perhaps a 
> few thousand image blobs in the db? (I run sqlite)
> There has got to be a reason why folk have wanted to migrate from a file 
> system store to a db store......
>
>
> Secondly......
> I have an application where users can upload a "banner image" into the 
> database, as follows:
>
>   ........
>   
> Field('banner','upload',requires=IS_EMPTY_OR(IS_IMAGE(minsize=(100,100),maxsize=(1000,200),
>   extensions=('png','jpeg','jpg'))),uploadfield='banner_image'),
>   Field('banner_image','blob'),
>   ...........
>
> I only have maybe 250 images thus far. But the volume of the banners might 
> become greater than I had originally scoped (over time), so I am wondering 
> it would be better to migrate this to store the banner images on the file 
> system.
>
> If my thought-process about using the file system is correct, is there an 
> easy way to do this?
>
> I guess I have to change the model to be
>   ........
>   
> Field('banner','upload',requires=IS_EMPTY_OR(IS_IMAGE(minsize=(100,100),maxsize=(1000,200),
>   
> extensions=('png','jpeg','jpg'))),uploadfolder=os.path.join(request.folder,'static/images/banners'),uploadseparate=True),
>   Field('banner_image','blob'),   
>   #I can leave the blob there as sqlite doesn't drop it anyway (I can 
> always update the records to None)
>   ...........
>
> Then, I would have to pull each image and store it in the file system
> I assume the filename is in <table>.banner, and the image is in 
> <table>.banner_image ??
> I think the download() function returns a URL only, whereas I need to pull 
> the image
>
> Is this possible (and easy) to do? 
> Actually, I don't mind if the 250 or so images I have at the moment are 
> stored directly in static/images/banners and that only future uploads will 
> be managed with uploadseparate=True.
>
> I am sure I can figure out a script to do this (unless someone has one 
> already), but the experts on this forum might tell me it is really best to 
> store these in the database after all.
>
> I have 2.9.5 and sqlite (btw, I have not migrated to mysql (yet!!), 
> because the transaction rate is quite low).
>
> Thanks as always. I'm forever learning....
> Simon
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to