Discussion:
[Erp5-dev] storing binary data in content objects
bartek
2007-11-20 11:32:45 UTC
Permalink
Hello

I tried to use the content storage mechanism - the one that works so
nicely for email, phone number, career etc - to store a picture (e.g. an
image of a person). Tried to define a property normally:

{ 'id' : 'picture'
, 'storage_id' : 'default_picture'
, 'description' : 'The current picture of the person'
, 'type' : 'content'
, 'portal_type' : ( 'Image', )
, 'acquired_property_id' : ( 'file', 'data')
, 'mode' : 'w'
},

and added a FileField named "my_picture_file" or
"my_default_picture_file" to a Person_view form.

But it doesn't work as expected - when I upload a file to a Person
object, the system creates an Image object named "default_picture" but
the "data" attribute of the Image contains file name instead of data.

And I'm confused - I thought that ERP5 would create a content object and
just pass on what it received to the object's setter method, but
apparently it does something else in the meantime. Any hint?

Bartek
--
"feelings affect productivity. (...) unhappy people write worse
software, and less of it."
Karl Fogel, "Producing Open Source Software"
Jérome Perrin
2007-11-23 16:05:05 UTC
Permalink
Post by bartek
Hello
I tried to use the content storage mechanism - the one that works so
nicely for email, phone number, career etc - to store a picture (e.g. an
{ 'id' : 'picture'
, 'storage_id' : 'default_picture'
, 'description' : 'The current picture of the person'
, 'type' : 'content'
, 'portal_type' : ( 'Image', )
, 'acquired_property_id' : ( 'file', 'data')
, 'mode' : 'w'
},
and added a FileField named "my_picture_file" or
"my_default_picture_file" to a Person_view form.
But it doesn't work as expected - when I upload a file to a Person
object, the system creates an Image object named "default_picture" but
the "data" attribute of the Image contains file name instead of data.
And I'm confused - I thought that ERP5 would create a content object and
just pass on what it received to the object's setter method, but
apparently it does something else in the meantime. Any hint?
Hello,

You should use ERP5/PropertySheet/DefaultImage.py
I think what's missing is this line:
'acquisition_accessor_id' : 'getDefaultImageValue',

J?rome
bartek
2007-11-24 14:48:44 UTC
Permalink
Post by Jérome Perrin
Post by bartek
Hello
I tried to use the content storage mechanism - the one that works so
nicely for email, phone number, career etc - to store a picture (e.g. an
{ 'id' : 'picture'
, 'storage_id' : 'default_picture'
, 'description' : 'The current picture of the person'
, 'type' : 'content'
, 'portal_type' : ( 'Image', )
, 'acquired_property_id' : ( 'file', 'data')
, 'mode' : 'w'
},
and added a FileField named "my_picture_file" or
"my_default_picture_file" to a Person_view form.
But it doesn't work as expected - when I upload a file to a Person
object, the system creates an Image object named "default_picture" but
the "data" attribute of the Image contains file name instead of data.
And I'm confused - I thought that ERP5 would create a content object and
just pass on what it received to the object's setter method, but
apparently it does something else in the meantime. Any hint?
Hello,
You should use ERP5/PropertySheet/DefaultImage.py
'acquisition_accessor_id' : 'getDefaultImageValue',
What was really missing, was some grey cells in my brain :) I forgot to
set form encoding to multipart...

B.
Post by Jérome Perrin
J?rome
_______________________________________________
Erp5-dev mailing list
Erp5-dev at erp5.org
http://mail.nexedi.com/mailman/listinfo/erp5-dev
--
"feelings affect productivity. (...) unhappy people write worse
software, and less of it."
Karl Fogel, "Producing Open Source Software"
Loading...