How can I upload a file with php with metadata
Hi, I have a problem, I can upload a file with normal metadata, but I have a subtype of metadata like this:
<xs:sequence>
<xs:element name="item" type="nxs:content" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element name="item" type="nxs:exampleListType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element name="field_01" type="xs:string"/>
<xs:element name="field_02" type="xs:string"/>
<xs:element name="field_03" type="xs:string"/>
<xs:element name="field_04" type="xs:string"/>
<xs:element name="field_05" type="xs:string"/>
</xs:sequence>
and I trying to upload a file adding metadata like this:
$answer= $session->newRequest("Document.Create")
->set('input', 'doc:' . $array1['PATH'])
->set('params', 'type', 'example_doc')
->set('params', 'name', $array2['name'])
->sendRequest();
$ls_path = $answer->getDocument(0)->getPath();
$ls_UID = $answer->getDocument(0)->getUid();
$answer= $session->newRequest("Document.SetProperty")
->set('input', 'doc:' . $ls_path)
->set('params', 'value', $array2['name'])
->set('params', 'xpath', 'dc:title')
->sendRequest();
how can I do for upload a file to nuxeo with subtype and his properties? thanks
Hi, You should be able to create your document with metadata and then attach a file with the following code:
$answer = $session
->newRequest('Document.Create')
->set('input', 'doc:/default-domain/workspaces/Default Workspace')
->set('params', 'type', 'Article')
->set('params', 'name', 'doc01')
->set('params', 'properties', 'dc:title=doc01
article:exampleList=[{"field01":"val001","field02":"val002","field03":"val003"}]')
->sendRequest();
$answer = $session
->newRequest('Blob.Attach')
->set('params', 'document', $answer->getDocument(0)->getPath())
->loadBlob('test.txt', 'text/plain')
->sendRequest();
Some references:
http://explorer.nuxeo.com/nuxeo/site/distribution/Nuxeo%20DM-8.3/viewOperation/Document.Create
Have you try the 'AddEntryToMultivaluedProperty' operation:
foreach ($array2 as $item)
{
$answer= $session->newRequest("AddEntryToMultivaluedProperty")
->set('input', 'doc:' . $ls_path)
->set('params', 'value', $item)
->set('params', 'xpath', 'Your:list_parameter')
->sendRequest();
}
or the 'Document.AddItemToListProperty' operation?
Thanks for the answer. I explained it wrong, I can upload the file but I can't set some metadata. For example: I can set typical metada like creator etc, but I can't set metadata which containing a list or type which more fields.
With this code I can set normal metadata and it works:
$answer= $session->newRequest("Document.SetProperty")
->set('input', 'doc:' . $ls_path)
->set('params', 'value', $array2['name'])
->set('params', 'xpath', 'dc:title')
->sendRequest();
But I don't know how can I insert a metadata which contains other fields of metadata like xml I put at first post. I can't do screenshot now, but for example If I have a file that represents a book in nuxeo, and this book has many authors, I have a complexType called author with his fields like name, gender etc. How I can set this fields?
You should try the “Blob.Attach” operation. For instance like this:
$answer= $session->newRequest("Document.Create")
->set('input', 'doc:' . $array1['PATH'])
->set('params', 'type', 'example_doc')
->set('params', 'name', $array2['name'])
->sendRequest();
$ls_path = $answer->getDocument(0)->getPath();
$ls_UID = $answer->getDocument(0)->getUid();
$ls_doc = $answer->getDocument(0);
$answer= $session->newRequest("Document.SetProperty")
->set('input', 'doc:' . $ls_path)
->set('params', 'value', $array2['name'])
->set('params', 'xpath', 'dc:title')
->sendRequest();
//We upload the file
$result = $session->newRequest("Blob.Attach")
->set('params', 'document', $ls_doc->getPath())
->loadBlob($FilePath, $FileMimotype)
->sendRequest();
where:
- $array1['PATH'] - is a folder path in nuxeo
- $array2['name'] - is a name of file
- 'example_doc' - should be 'file'
- $FilePath - is a full local path of file
- $FileMimotype - something like “application/pdf” or “application/msword”