[Zope] Application Design and Photos

Cliff Ford Cliff.Ford at ed.ac.uk
Thu Nov 4 18:10:35 EST 2004


I put some 'full-size' pictures on the web myself recently, varying in 
size from 1 to 2Mb! So maybe a Product is a good idea if you want to 
auto-resize to some reasonable maximum. Some other thoughts:

My helpers tell me it is a lot easier to back up a file system with a 
lot of small files than a bloated ZODB. So put the images in the 
filesystem rather than the ZODB or MySQL database.

It is surprisingly easy to write an Extension to stow files in the file 
system, like this:

from os import remove

def putDocument(filename, content):
     file = '/path/to/your/storage/place/'+filename
     output = open(file, 'w')
     output.write(content)
     output.close()

def getDocument(filename):
     file = '/path/to/your/storage/place/'+filename
     input = open(file, 'r')
     content = input.read()
     input.close()
     return content

def deleteDocument(filename):
     file = '/path/to/your/storage/place/'+filename
     remove(file)

I just base a filename on a MySQL auto_increment field, and fetch like this:

for result in context.getDocumentSQL():
     (type, encoding) = context.getMimeType(result.Filename)

     theFilename = 'DA%s' % context.REQUEST.SerialNo
     context.REQUEST.RESPONSE.setHeader('Content-Type', type)
     return context.getDocument(theFilename)

and getMimeType is another Extension:

import mimetypes

def getMimeType(filename):

     return mimetypes.guess_type(filename)

So this is generic, handling jpg, pdf, etc.

Typically, images are downloaded after the page, and I doubt whether you 
want to trigger login to fetch an image - so don't put the image link in 
a page if the user is not logged in, and put some code in the fetch 
script to send a simple placeholder image if the user is not logged in.

Cliff


Gregor Melhorn wrote:
> Hello Zope users!
> 
>  
> 
>  
> 
> Maybe you can help me with the following scenario:
> 
>  
> 
> I'm developing a community site in zope. I don't use CMF or Plone, since I
> wouldn't be using much of the functionality anyway and therefore would only
> slow down the site with it. All user data is stored in MySQL. exUserFolder
> is used for authentication. 
> 
>  
> 
> Registered users should be able to upload photos to my site. These photos
> may be viewed by other registered users, but no anonymous users (no
> anonymous access to photos allowed).
> 
>  
> 
> Now, how do I do this best? 
> 
>  
> 
> Is there any "best practice" on how to give each user a personal gallery? 
> 
>  
> 
> Creating a single folder for every user, and putting images in there for
> every category? Or should I put all in one big folder, maybe assigning
> matching photos to users via a table in the database with user-filename
> columns?
> 
>  
> 
> There may be around 30 000 users and 200 000 photos. I thought of using the
> "Photo Folder" product, maybe setting its properties to "external
> filesystem", so the ZopeDB doesn't get too large. Anybody has experience on
> that one? Is it possible to use the external filesystem and still prevent
> anonymous access?
> 
>  
> 
> Any help would be appreciated!
> 
>  
> 
> Gregor
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )


More information about the Zope mailing list