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
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.
Any suggestions on how best to do this?
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();