I am trying to upload file from android app and want to write that data to our server(saving file to our server) I am able to write to a file but that image won't display
My code of snippet:-
var data='';
req.setEncoding('binary'); // also try UTF8
req.on('data', function(chunk) {
data += chunk;
// f.write(chunk);
});
req.on('end', function() {
let fileData = {};
fileData.filename = filename;
fileData.fileextension = fileextension;
fs.writeFile(completeFilename, data, 'binary', function (err) {
if(err){
console.log(err);
let response_data = status_codes.file_uplpoad_error;
console.log(response_data);
let enc = encrypt_decrypt.encrypt(cryptkey, iv, JSON.stringify(response_data));
res.end(enc);
}else{
let fileData = {};
fileData.filename = filename;
fileData.fileextension = fileextension;
return callback(fileData);
}
});
});
req.on('error', function(err) {
// This prints the error message and stack trace to `stderr`.
console.error(err.stack);
console.log(err);
res.end('error');
});
Where I am getting wrong unable to know as everything worked wellexcept writing of image
Tried all things but unable to get it done Thanks in advance :)
via VIKAS KOHLI
No comments:
Post a Comment