Thursday 4 May 2017

How we solve remote stream read-write related error when uploading any file using Nodejs?

In one of my project I try to upload more than one file using nodejs without page reload from apache side. For file upload code from Apache side is like below:

var socket = io.connect(nodejsaccesspath,{});
var stream = ss.createStream();
ss.forceBase64 = true;

socket.emit('request-to-edit-a-reaction',{requesterID:currentUserIdForNodejs, dateTime:dateTime});
ss(socket).emit('openhouse-documents-reaction', stream, {name: userFileOfReactAnAnswer.name, size: userFileOfReactAnAnswer.size, attachedFilePath:filePathForReaction});

blobStream = ss.createBlobReadStream(userFileOfReactAnAnswer);
var size = 0;
var attachmentPercentage = 0;
blobStream.on('data', function(chunk) {
size += chunk.length;
// below code show attachment sending status percentage   
attachmentPercentage = Math.floor(size / userFileOfReactAnAnswer.size * 100) + '%';
jQuery(element).parents('.each_reaction_li').find(".send_upload_status .file_upload_status_outer .file_upload_status_inner").css("width",attachmentPercentage);
});

blobStream.pipe(stream);
// when success come from nodejs
stream = null;
blobStream = null;

And the nodejs server side the code is like below:

var serverSideCallback19 = function serverSideCallback19(editedReactionData) {
ss(client).on('openhouse-documents-reaction', function(stream, data17) {
    var currentdate = new Date();
    var currentTime = currentdate.getTime();
    var filename = (data17.attachedFilePath)+ currentTime + "_" +path.basename(data17.name);
    stream.pipe(fs.createWriteStream(filename)).on('finish', function() {

    }); 
});
}
client.on( 'request-to-edit-a-reaction', serverSideCallback19);

When first time any file was upload then no problem occur, but next time when user try to upload any file then below error come:

.../node_modules/socket.io-stream/lib/iostream.js:97

this.socket._read(this.id, size); ^

TypeError: Cannot read property '_read' of null

at IOStream._read (.../node_modules/socket.io-stream/lib/iostream.js:97:14)

at IOStream.Readable.read (_stream_readable.js:350:10)

at resume_ (_stream_readable.js:739:12)

at _combinedTickCallback (internal/process/next_tick.js:80:11)

at process._tickCallback (internal/process/next_tick.js:104:9)

Could anyone have any idea about how to solve this problem?

Thanks in advance.



via Goutam Dolai

No comments:

Post a Comment