09-15-2017 07:37 AM
Advance thanks for any help.
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.
** message: "redirect location header missing at: http://nuxeohost:8060/nuxeo/api/v1/repo/default/upload/batchId-50b855a8-b789-4b5a-a413-0e7442bcd489/...; name: "FetchError" stack: undefined type: "invalid-redirect" **
function initializeBatchId(){
var batchRequest = client.request('/upload');
batchRequest.post()
.then(function(res){
batchId = res.batchId;
for(var j=0 ; j<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);
})
}
Attention: Blogs & Forums are in READ-ONLY mode from Oct 9-19 as we transition to our new platform. Learn more.
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.