Skip to content Skip to sidebar Skip to footer

Send A Multipart Request From A Device To Server In Node.js

I am receiving a video bytes from a device, and it should be a multipart request. Its a post api which is created in node.js. How can I recieve a multipart request in post api in n

Solution 1:

You need to append a separator after video bye string like following

if byte string are - 'abcdefghijklmnopqrstuvwxyz';

then you need to append any separator(#####) like this to identify end of complete string

now your request string will be like this - 'abcdefghijklmnopqrstuvwxyz'+'#####';

Now your request string having a end separator(#####) from which you can identify your complete chunks

var video_byte_string = req.param('videoByteStr');
isCorrectString = false;
data_stream += video_byte_string;
var n = data_stream.lastIndexOf("#####");
if (n === -1) {
    var steamArr= data_stream.split("#####");
    var completeByteString = steamArr[0];
    isCorrectString = true;
}

if(isCorrectString) {

    var writeStream = gfs.createWriteStream({mode:'w',content_type: 'video/mov'});
    var buffer = new Buffer(completeByteString).toString('base64');
    var response = streamifier.createReadStream(buffer).pipe(writeStream);
}

Thanks

Post a Comment for "Send A Multipart Request From A Device To Server In Node.js"