Nuxeo mailing list archives
[Nuxeo-tickets] Re: [Nuxeo Repository] #1591: Error creating "News
Item" with photo in CPSRemoteController
Nuxeo Repository
trac at nuxeo.com
Wed Oct 25 16:33:04 CEST 2006
#1591: Error creating "News Item" with photo in CPSRemoteController
----------------------------------+-----------------------------------------
Reporter: juan.lago at iavante.es | Owner: rspivak
Type: defect | Status: new
Priority: P1 | Milestone: CPS 3.4.3
Component: CPSRemoteController | Version: 3.4.0
Severity: normal | Resolution:
Keywords: |
----------------------------------+-----------------------------------------
Comment (by tracguest):
I have had the same problem and I have found a possible solution.
I have implemented a patch (attached file) that modify the
RemoteControllerTool module:
1. Add a constant key "BINARY_FILE_TYPE = 'file_type'" to define the
type of the uploaded file (It is suppose to be a File object, but if we
want to upload Images we have to make a distinction).
2. New implementation of the _editDocument method, where we have to get
the file_type variable from the doc_def dictionary:
{{{
file_type = doc_def.get(BINARY_FILE_TYPE,None)
}}}
3. And where we check whether the file is an Image or a File (in
_editDocument as well):
{{{
...
if file is not None:
if isinstance(file, Binary):
file_id = generateFileName(file_name)
# Checking whether the file is an Image/Photo or a File
if file_type is 'Image' or 'Photo':
doc_def[file_key] = Image(file_id, file_name,
file.data)
else:
doc_def[file_key] = File(file_id, file_name, file.data)
elif isinstance(file, File):
# CPSDistantPublisher is able to directly send File
instances
doc_def[file_key] = file
...
}}}
In a test:
{{{
...
f = open('<image.gif>')
binary = Binary(f.read())
f.close()
...
doc_def = {'Title': <doc_title>,
'Description': <doc_desc>,
'file' : binary,
'file_name' : <photo_name>,
'file_key' : 'photo',
'file_type' : 'Image',
}
try:
proxy.createDocument('News Item', doc_def, 'workspaces', 0, 'No
comment')
except:
print 'Error'
...
}}}
where:
* "<doc_type>" is the type of the document to be created.
* "<doc_def>" is a dictionary containing the document data:
* "Title" is the title of the document
* "Description" is the document description
* "file" is the binary instance of the uploaded image.
* "file_name" is the name of the uploaded file.
* "file_key" is the name of the ATTRIBUTE where the image is
going to be stored (schema!).
* "file_type" is the type of the uploaded file: Image/Photo or
File
After these changes, the test create a 'News Item' with image with no
problem.
--
Ticket URL: <http://svn.nuxeo.org/trac/pub/ticket/1591>
Nuxeo Repository <http://www.cps-project.org/>
Nuxeo Repository
This list archive provided by Nuxeo, the
leaders of open source ECM.
Check out the Nuxeo 5 open source,
standards-based ECM project.