The error you see is unrelated to image storing in the ZODB.
To store larger pieces of data, you really want to use a ZODB Blob
instead of putting the image data directly in an attribute. Blob
s are stored separately on disk and do not flush the ZODB cache, and can be streamed back to the client on access again.
To create and store a Blob
, use:
from ZODB.blob import Blob
uid = Blob(imagebinary.read())
Once created like that, you can later use uid
as a file; you need to open it in read or write mode first. To return the contents of the blob from a view, for example, use:
from pyramid.response import Response
def serveimage(request):
# retrieve uid from somewhere
resp = Response(content_type='image/jpeg')
resp.app_iter = uid.open('r') # open for reading
return resp
Blobs are bound to transactions and changes to them are automatically discarded if the transaction is rolled back.