I'm working on file uploading and want to chunk upload files to the server,
but when i combined the chunked files, the file hash changed(diff from the
orignal hash). There might be some mistakes. Please help. thx thx.
There is a strange thing that if I upload the chunk file with chunk size
larger than 11.4% of the file size, will got the hash correctly. Im on
nodejs 0.10.6 now.
*My client side code:*
function putFile(fileStat){
putChunks(fileStat.totalChunkNumber);
function putChunks(totalChunkNumber){
for(var i = 1; i <= totalChunkNumber; i++){
putChunkFile(fileStat, i)
}
}
}
function putChunkFile(fileStat, chunkNumber){
var filePath = fileStat.filePath;
var _start = (chunkNumber - 1) * CHUNK_SIZE;
var _end = _start + CHUNK_SIZE -1;
if (_end >= fileStat.fileSize){
_end = fileStat.fileSize;
}
var req = createRequest("/testfiles", "PUT",
{
'X-Chunk-Number': chunkNumber,
'X-Chunk-Size': _end - _start + 1
});
var sourceStream = fs.createReadStream(filePath, {start: _start, end:
_end});
sourceStream.on("open", function(){
sourceStream.pipe(req);
});
sourceStream.on("end", function(){
req.end();
});
}
*Server side code:*
exports.put = function(req, res){
var list = []
var length = 0;
req.on("data", function(data){
list.push(data);
length += data.length;
}).on("end",function(){
var buffer = Buffer.concat(list, length);
fs.writeFile(path.join(getFilePath(), 'part' +
req.headers['x-chunk-number']), buffer, function(){
res.status(200);
res.write('uploaded ' + req.headers['x-chunk-number']);
res.end();
});
});
}
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.