02-18-2016 08:52 AM
Hi, I am trying to upload a file using nuxeo client. Initialy I have created the client like below var client = new nuxeo.Client({ baseURL: nuxeo_url, username: cms_user, password: cms_password }); client.schemas(['dublincore', 'file']); For uploading a file in nuxeo 7.10 first I am creating a document and uploading the file and then attaching to the created document please find the snippet for the same. Upto uploader.uploadFile(file, function (fileIndex, file,timeDiff) function the flow is working but after that I am not getting any response. Please help me how to fix this. Thanks a lot.
var file = request.files.file,
path = './uploads/'; ///var/cv/ams/uploads/';
var buffer = file.buffer, // Note: buffer only populates if you set
mimetype = file.mimetype,
fileName = file.name;
file = fs.createReadStream(path + fileName);
//logger.debug("File content : " + JSON.stringify(file));
logger.debug('Batch Id : ' + batchId + ' mime type : ' + mimetype + ' file name : ' + fileName);
var fileIndex = 0;
client.operation('Document.Create').params({
type: type,
name: fileName,
properties: 'dc:title=My Asset \ndc:description=A Test Asset'
})
.input('doc:' + base_workspace + '/' + workspace)
.execute(function (error, data) {
if (error) {
logger.error('Error : ' + error);
logger.error('Error : ' + JSON.stringify(error));
// something went wrong
throw error;
}
var uploader = client.operation("Blob.Attach")
.params({
document: data.uid,
save: true,
xpath: "file:content"
})
.uploader();
logger.debug('Created ' + data.uid + ' uploader :');
// Upload the file
uploader.uploadFile(file, function (fileIndex, file,timeDiff) {
// When done, execute the operation
logger.debug("inside upload");
uploader.execute(function (error, data) {
logger.debug("inside execute");
if (error) {
// something went wrong
logger.error('Error : ' + error);
throw error;
}
response.setHeader("Content-Type", "application/json");
response.write(data);
logger.info("attaching completed..");
/>
logger.debug('Uploaded ' + JSON.stringify(data));
response.end();
// successfully attached blob
});
});
});
file = fs.createReadStream(path + fileName); //console.log("File content : " + JSON.stringify(file)); //response.end(); },
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.