Add attchments using CSV import

Attachments can be added when creating documents from “Files tab”, i want to do the same thing using a CSV file so i wonder what should I add as a property that refers to attachments in the CSV file. I'm able to add the Main File using “file:content” property , I've tried to add “files:file:content” but it's not working. Any idea about this ?

0 votes

1 answers



I'm not sure to understand your question, but the "files" schema does not work like the "file" schema. "file" does have two attributes named filename and content, but files does not. It contains a list of items names files, with each item having two attributes: filename and file. The correct xpath to reach a value from the files schema would be something like "files:files/0/file". This one would give you the blob content for the first file stored in the "files" list.

Thank you Greg Drayon for replying , can you tell me how can i use "files:files/0/file" in csv file to import attachment as well. I've tried adding "files:files/0/file" but files aren't imported and i'm not getting errors

Okay, thank you so much Greg Drayon

Note that file:filename has been deprecated for a while and will be removed soon. You should use file:content/name instead.

Thank you for the update. My knowledge might be a little bit outdated.

Short answer: after a closer look to the CSV Import bundle, in the CSVImporterWork class, there doesn't seem to have any way to handle another blob proeprty than the "file:content" one or, at least, one which is not part of a list or complex type property and still named "content".

Explanation (but I might be wrong): "files:files" is an array property, so should be handled as such in the CSV file. So, it SHOULD be something like: Header: files:files In the CSV line: "[{\"filename\":\"name for file 1\",\"file\":\"file1.pdf\"},{\"filename\":\"name for file 2\",\"file\":\"file2.docx\"}]"

This is how it SHOULD be, from my understanding on how it works. As it is an array property, it would be handled by the "fieldType.isListType()" part, and then handled as a simple array, and not an array which could contain blobs to handle. I tried the line I give before and I get an exception:

java.lang.ClassCastException: org.codehaus.jackson.node.TextNode cannot be cast to org.codehaus.jackson.node.ObjectNode
    at org.nuxeo.ecm.automation.core.util.ComplexTypeJSONDecoder.decode(

It means that the program tries to use a string as an object. So it does evaluate the \"file\":\"file1.pdf\" as if it would be for a string property, not a blob.

As it is right now, I'm not sure the CSV importer can handle your case, except by modifying it.

0 votes