upload blob/byte[]

Hello everyone, Is it possible to upload a file by just blob or byte [] instead of the file itself ??? See the example below:

private Document exportNuxeo() throws IOException {


        Document doc = new Document("file", "File");
        doc.set("dc:title", "Documento 1");

        doc = nuxeoClient.repository().createDocumentByPath("/camara.leg/workspaces/", doc);

        Document docCriado = nuxeoClient.repository().fetchDocumentByPath("/camara.leg/workspaces/file");

        Blob fileBlob = new Blob(new File("c:\\Desenvolvimento\\doc-nuxeo\\teste.pdf"));

        nuxeoClient.automation().newRequest("Blob.AttachOnDocument").param("document", docCriado).input(fileBlob)
                .execute();

        return doc;
    }
```
Blob fileBlob = new Blob(new File("c:\\Desenvolvimento\\doc-nuxeo\\teste.pdf"));

Instead of being the File object being, I use a Blob or byte []

Because I will need to migrate multiple files from the sql server database to nuxeo….

att Ana Paula Lopes Araújo

0 votes

1 answers

1839 views

ANSWER

someone???
03/28/2017



Hello,

This is currently not possible with our java client. I created https://jira.nuxeo.com/browse/JAVACLIENT-125 to add this feature to client. But it may take times to be done. You can create a PR with the feature if you want, have a look at https://doc.nuxeo.com/nxdoc/contributing-to-nuxeo/ before.

Unless, I'm afraid you need to serialize the byte[] to a file in order to upload it. Something like this should work:

FileUtils.writeByteArrayToFile(new File("pathname"), myByteArray)

FileUtils is a class from Apache Common IO, used by the client.

0 votes



I need to migrate some files (+/- one million and a half) that are in SQL Server to nuxeo …

Any suggestions on how best to do this?

03/28/2017

I would have these files in blob or byte []
03/28/2017

The only way to do this is to write the blob or byte[] to a temporary file and then upload this file by using blob object from nuxeo-java-client. Blob object from Nuxeo has getByteArray() method which allows you to easily factorize your code by writing these bytes to a temporary file.
03/28/2017

Do you have any examples using this getByteArray() ???? and could you share it for me?
03/28/2017

This isn't nuxeo-related, it's just pure java code. Something like this should work:

// your parameters
Document doc = ...;
String fileName = ...;
byte[] bytes = ...; // here you can use org.nuxeo.ecm.core.api.Blob.getByteArray()

// Serialize bytes to a temporary file
Path path = Files.createTempFile("bytes-", fileName);
File file = path.toFile();
org.apache.commons.io.FileUtils.writeByteArrayToFile(file, bytes);

// upload it
Blob blob = new Blob(file);
nuxeoClient.automation().newRequest("Blob.AttachOnDocument").param("document", doc).input(blob)
                   .execute();
03/29/2017