<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Mulpile file upload using node js in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/mulpile-file-upload-using-node-js/m-p/326361#M13362</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I am able to upload single image using nodejs to nuxeo server.
But am not able to upload multiple images.
Please let me know how to upload multiple file.&lt;/P&gt;
&lt;P&gt;Below is my code for file upload.&lt;/P&gt;
&lt;P&gt;uploadContent : function(request, response, next) {		
var headers = request.headers;
var body = request.body;
var batchId = uuid.v1();
var customer = headers.customer;
var type = request.query.type;
if(customer === undefined){
console.log("customer is not set in header, expected to set as query parameter..");
customer = request.query.customer;
if(customer === undefined){
console.log("customer is not set..");
response.end();
return;
}
}&lt;BR /&gt; /&amp;gt;
if(type === undefined){
console.log("As Content Type is not set as type query parameter, it's setting default Picture");
type = "Picture";
}&lt;BR /&gt; /&amp;gt;
var workspace = customer + "-workspace";
var folderPath;
folderPath = request.query.path;		
if(folderPath === undefined) {
folderPath = "";
}
console.log("Folder Path : "+folderPath);
var file = request.files.file, path = './uploads/';///var/cv/ams/uploads/';
console.log("file = "+file);
console.log("path = "+path);
var buffer = file.buffer, // Note: buffer only populates if you set
// inMemory: true.
fileName = file.name;
console.log("File name : "+fileName);
console.log("Buffer : "+buffer);
console.log('Batch Id : '+batchId);
rest.post(
nuxeo_base_url + 'automation/batch/upload',
{
multipart : true,
username : cms_user,
password : cms_password,
headers : {
'X-Batch-Id' : batchId,
'X-File-Idx' : '0',
'X-File-Name' : fileName
},
data : {
'file' : rest.file(path + fileName, fileName, file.size,
file.encoding, file.mimetype)
}
}).on('complete', function(result) {
if (result instanceof Error) {
console.log('Error:', result.message);
this.retry(5000); // try again after 5 sec
} else {
//response.setHeader("Content-Type", "application/json");
//response.write(result);
console.log('Uploading has been done for batch : '+batchId);
//console.log(result);
//response.end();
var url = base_url + '/path' + base_workspace + '/' + workspace + "/" + folderPath;
console.log(url);
var data = '{"entity-type": "document", "name": "' + fileName + '", "type": "' + type + '", "properties": {"dc:title": "' + fileName + '", "dc:description": "", "file:content": {"upload-batch":"' + batchId +'", "upload-fileId":"0"}}}';
rest.post(
url,
{
username : cms_user,
password : cms_password,
headers : {
'Content-Type' : 'application/json'
},
data : data
}).on('complete', function(result) {
if (result instanceof Error) {
console.log('Error:', result.message);
this.retry(5000); // try again after 5 sec
} else {
response.setHeader("Content-Type", "application/json");
response.write(result);
console.log("Uploading completed..");&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;					response.end();
				}
			});
		}
	});
},
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Nov 2015 05:27:31 GMT</pubDate>
    <dc:creator>Ramakrishna_Gad</dc:creator>
    <dc:date>2015-11-05T05:27:31Z</dc:date>
    <item>
      <title>Mulpile file upload using node js</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/mulpile-file-upload-using-node-js/m-p/326361#M13362</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I am able to upload single image using nodejs to nuxeo server.
But am not able to upload multiple images.
Please let me know how to upload multiple file.&lt;/P&gt;
&lt;P&gt;Below is my code for file upload.&lt;/P&gt;
&lt;P&gt;uploadContent : function(request, response, next) {		
var headers = request.headers;
var body = request.body;
var batchId = uuid.v1();
var customer = headers.customer;
var type = request.query.type;
if(customer === undefined){
console.log("customer is not set in header, expected to set as query parameter..");
customer = request.query.customer;
if(customer === undefined){
console.log("customer is not set..");
response.end();
return;
}
}&lt;BR /&gt; /&amp;gt;
if(type === undefined){
console.log("As Content Type is not set as type query parameter, it's setting default Picture");
type = "Picture";
}&lt;BR /&gt; /&amp;gt;
var workspace = customer + "-workspace";
var folderPath;
folderPath = request.query.path;		
if(folderPath === undefined) {
folderPath = "";
}
console.log("Folder Path : "+folderPath);
var file = request.files.file, path = './uploads/';///var/cv/ams/uploads/';
console.log("file = "+file);
console.log("path = "+path);
var buffer = file.buffer, // Note: buffer only populates if you set
// inMemory: true.
fileName = file.name;
console.log("File name : "+fileName);
console.log("Buffer : "+buffer);
console.log('Batch Id : '+batchId);
rest.post(
nuxeo_base_url + 'automation/batch/upload',
{
multipart : true,
username : cms_user,
password : cms_password,
headers : {
'X-Batch-Id' : batchId,
'X-File-Idx' : '0',
'X-File-Name' : fileName
},
data : {
'file' : rest.file(path + fileName, fileName, file.size,
file.encoding, file.mimetype)
}
}).on('complete', function(result) {
if (result instanceof Error) {
console.log('Error:', result.message);
this.retry(5000); // try again after 5 sec
} else {
//response.setHeader("Content-Type", "application/json");
//response.write(result);
console.log('Uploading has been done for batch : '+batchId);
//console.log(result);
//response.end();
var url = base_url + '/path' + base_workspace + '/' + workspace + "/" + folderPath;
console.log(url);
var data = '{"entity-type": "document", "name": "' + fileName + '", "type": "' + type + '", "properties": {"dc:title": "' + fileName + '", "dc:description": "", "file:content": {"upload-batch":"' + batchId +'", "upload-fileId":"0"}}}';
rest.post(
url,
{
username : cms_user,
password : cms_password,
headers : {
'Content-Type' : 'application/json'
},
data : data
}).on('complete', function(result) {
if (result instanceof Error) {
console.log('Error:', result.message);
this.retry(5000); // try again after 5 sec
} else {
response.setHeader("Content-Type", "application/json");
response.write(result);
console.log("Uploading completed..");&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;					response.end();
				}
			});
		}
	});
},
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Nov 2015 05:27:31 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/mulpile-file-upload-using-node-js/m-p/326361#M13362</guid>
      <dc:creator>Ramakrishna_Gad</dc:creator>
      <dc:date>2015-11-05T05:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Mulpile file upload using node js</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/mulpile-file-upload-using-node-js/m-p/326362#M13363</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You need to upload each files on the same &lt;CODE&gt;batchId&lt;/CODE&gt; but with a different &lt;CODE&gt;X-File-Idx&lt;/CODE&gt; header (0, 1, 2, ...).&lt;/P&gt;
&lt;P&gt;You can have a look at this video explaining how to upload files and use them while creating a document: &lt;A href="https://university.nuxeo.io/nuxeo/university/#!/course/working-with-nuxeo-platform-rest-api/importing-files-rest-api" target="test_blank"&gt;https://university.nuxeo.io/nuxeo/university/#!/course/working-with-nuxeo-platform-rest-api/importing-files-rest-api&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;However, why are you not using the &lt;A href="https://www.npmjs.com/package/nuxeo"&gt;official npm package&lt;/A&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2015 10:32:52 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/mulpile-file-upload-using-node-js/m-p/326362#M13363</guid>
      <dc:creator>Thomas_Roger</dc:creator>
      <dc:date>2015-11-05T10:32:52Z</dc:date>
    </item>
  </channel>
</rss>

