<?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 unable to upload big file  ( &amp;gt; 2gb) using Nuxeo js client REST API in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/unable-to-upload-big-file-gt-2gb-using-nuxeo-js-client-rest-api/m-p/323216#M10217</link>
    <description>&lt;P&gt;Advance thanks for any help.&lt;/P&gt;
&lt;P&gt;I am trying to upload file of size more than 2gb by breaking the file into chunks (Resumable) and iterating through chunks and trying to upload each chunk at a time. But api is throwing following error.&lt;/P&gt;
&lt;P&gt;** message: "redirect location header missing at: &lt;A href="http://nuxeohost:8060/nuxeo/api/v1/repo/default/upload/batchId-50b855a8-b789-4b5a-a413-0e7442bcd489/0&amp;quot;" target="test_blank"&gt;http://nuxeohost:8060/nuxeo/api/v1/repo/default/upload/batchId-50b855a8-b789-4b5a-a413-0e7442bcd489/0"&lt;/A&gt;;
name: "FetchError"
stack: undefined
type: "invalid-redirect" **&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;function initializeBatchId(){
  var batchRequest = client.request('/upload');
  batchRequest.post()  
  .then(function(res){
    batchId = res.batchId;
    for(var j=0 ; j&amp;lt;Streamchunks.length; j++){
        i = j;           
        switch(j){
          case 0 :
          startIndex = 0;
          endIndex = 3407871;
          break;
          case 1 :
          startIndex = 3407872;
          endIndex = 3407872 + 3407871;
          break;
          case 2 :
          startIndex = 6815744;
          endIndex = 3407872 + 3407871 + 3670016;
          break;
          case 3 :
          startIndex = 3407872 + 3407871 + 3670015;
          endIndex = 3407872 + 3407871 + 3670016 + 3670016;
          break;
          case 4 :
          startIndex = 3407872 + 3407871 + 3670016 + 3670016;
          endIndex = file.size;
          break;
        }

       // if(i===0){
         // var filestream = fs.createReadStream(path + fileName,{start:0,end:3565158 }); // creats file stream
          var filestream = fs.createReadStream(path + fileName,{start:startIndex,end:endIndex,highWaterMark: 3565158  }); // creats file stream
          //var blob = new nuxeo.Blob({ content: filestream, name: fileName, mimeType: file.mimetype, size: file.size })
          upload(filestream);               
       // }
    }
  })
  .catch(function(error){
    console.log("error in fetching batchId")
  })    
}


function upload(stream){      
  var uploadRequest = client.request('/upload/'+batchId+'/0');
  uploadRequest.post({
    'headers':{
      'X-Upload-Type': 'chunked',
      'X-Upload-Chunk-Index': i,
      'X-Upload-Chunk-Count': Streamchunks.length,
      'X-File-Name':fileName,
      'X-File-Type':file.mimetype,
      'X-File-Size':file.size,
    },
    'body':stream
  })
  .then(function(res){
    //console.log(res);
    var nuxeoDocument = '{"entity-type": "document", "name": "' + fileName + '", "type": "' + type + '", "properties": {"dc:title": "' + fileName + '", "dc:description": "", "file:content": {"upload-batch":"' + batchId + '", "upload-fileId":"0"}}}'
    console.log("blob updated");
    nuxeoDocument = JSON.parse(nuxeoDocument);
    return client.repository()
    .create(parentId, nuxeoDocument, {'headers':{'X-NXDocumentProperties': '*'}})
  })
  .then(function(result){
    console.log("uploaded success");
    formAsset([result],function(array){
      result = array[0]
    })
    response.setHeader("Content-Type", "application/json");
    response.write(JSON.stringify(result));
    response.end();        
    fs.unlinkSync(path + fileName);
  })
  .catch(function(error){
    console.log(error);
  })
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 15 Sep 2017 11:37:55 GMT</pubDate>
    <dc:creator>Pradeep_Kumar</dc:creator>
    <dc:date>2017-09-15T11:37:55Z</dc:date>
    <item>
      <title>unable to upload big file  ( &gt; 2gb) using Nuxeo js client REST API</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/unable-to-upload-big-file-gt-2gb-using-nuxeo-js-client-rest-api/m-p/323216#M10217</link>
      <description>&lt;P&gt;Advance thanks for any help.&lt;/P&gt;
&lt;P&gt;I am trying to upload file of size more than 2gb by breaking the file into chunks (Resumable) and iterating through chunks and trying to upload each chunk at a time. But api is throwing following error.&lt;/P&gt;
&lt;P&gt;** message: "redirect location header missing at: &lt;A href="http://nuxeohost:8060/nuxeo/api/v1/repo/default/upload/batchId-50b855a8-b789-4b5a-a413-0e7442bcd489/0&amp;quot;" target="test_blank"&gt;http://nuxeohost:8060/nuxeo/api/v1/repo/default/upload/batchId-50b855a8-b789-4b5a-a413-0e7442bcd489/0"&lt;/A&gt;;
name: "FetchError"
stack: undefined
type: "invalid-redirect" **&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;function initializeBatchId(){
  var batchRequest = client.request('/upload');
  batchRequest.post()  
  .then(function(res){
    batchId = res.batchId;
    for(var j=0 ; j&amp;lt;Streamchunks.length; j++){
        i = j;           
        switch(j){
          case 0 :
          startIndex = 0;
          endIndex = 3407871;
          break;
          case 1 :
          startIndex = 3407872;
          endIndex = 3407872 + 3407871;
          break;
          case 2 :
          startIndex = 6815744;
          endIndex = 3407872 + 3407871 + 3670016;
          break;
          case 3 :
          startIndex = 3407872 + 3407871 + 3670015;
          endIndex = 3407872 + 3407871 + 3670016 + 3670016;
          break;
          case 4 :
          startIndex = 3407872 + 3407871 + 3670016 + 3670016;
          endIndex = file.size;
          break;
        }

       // if(i===0){
         // var filestream = fs.createReadStream(path + fileName,{start:0,end:3565158 }); // creats file stream
          var filestream = fs.createReadStream(path + fileName,{start:startIndex,end:endIndex,highWaterMark: 3565158  }); // creats file stream
          //var blob = new nuxeo.Blob({ content: filestream, name: fileName, mimeType: file.mimetype, size: file.size })
          upload(filestream);               
       // }
    }
  })
  .catch(function(error){
    console.log("error in fetching batchId")
  })    
}


function upload(stream){      
  var uploadRequest = client.request('/upload/'+batchId+'/0');
  uploadRequest.post({
    'headers':{
      'X-Upload-Type': 'chunked',
      'X-Upload-Chunk-Index': i,
      'X-Upload-Chunk-Count': Streamchunks.length,
      'X-File-Name':fileName,
      'X-File-Type':file.mimetype,
      'X-File-Size':file.size,
    },
    'body':stream
  })
  .then(function(res){
    //console.log(res);
    var nuxeoDocument = '{"entity-type": "document", "name": "' + fileName + '", "type": "' + type + '", "properties": {"dc:title": "' + fileName + '", "dc:description": "", "file:content": {"upload-batch":"' + batchId + '", "upload-fileId":"0"}}}'
    console.log("blob updated");
    nuxeoDocument = JSON.parse(nuxeoDocument);
    return client.repository()
    .create(parentId, nuxeoDocument, {'headers':{'X-NXDocumentProperties': '*'}})
  })
  .then(function(result){
    console.log("uploaded success");
    formAsset([result],function(array){
      result = array[0]
    })
    response.setHeader("Content-Type", "application/json");
    response.write(JSON.stringify(result));
    response.end();        
    fs.unlinkSync(path + fileName);
  })
  .catch(function(error){
    console.log(error);
  })
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Sep 2017 11:37:55 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/unable-to-upload-big-file-gt-2gb-using-nuxeo-js-client-rest-api/m-p/323216#M10217</guid>
      <dc:creator>Pradeep_Kumar</dc:creator>
      <dc:date>2017-09-15T11:37:55Z</dc:date>
    </item>
  </channel>
</rss>

