0
我想從android應用程序上傳文件,並希望將該數據寫入我們的服務器(保存文件到我們的服務器) 我可以寫入文件,但該圖像不會顯示從android應用程序寫入圖像數據到節點js服務器
我的代碼片段: -
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');
});
已嘗試過所有的東西,但不能把它做 在此先感謝:)
所以從android我編碼的圖像數據爲base64,然後解碼從base64 –
@VIKASKOHLI是的確切 – sasan