このAndroidアプリはCordova-2.2.0でビルドされており、サーバー側のノードを使用しています。カメラまたはファイルからサーバーに画像を送信する必要がある部分があります。画像はサーバーに正常にアップロードされましたが、保存すると破損しているようです。メモ帳で画像を開くと、ファイルにこの「余分なヘッダー」があります。その上、すべてのファイルはまったく同じです。これがクライアント上の私のコードです:
function getPhoto() {
navigator.camera.getPicture(uploadPhoto,
function(message) { alert('No image selected');},
{ quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
);
}
function uploadPhoto(imageURI) {
var largeImage = document.getElementById('Image');
largeImage.style.display = 'block';
largeImage.src = imageURI;
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpg";
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://10.8.13.92:8082", win, fail, options);
}
そしてこれはサーバー上のコードです:
http.createServer(function (req,res){
var fs = require('fs');
var imagen = fs.createWriteStream("imagen.jpg",{'flags':'a'});
req.addListener('response',function(response){
})
});
req.addListener('data',function(chunk){
imagen.write(chunk,encoding='binary');
});
req.on('end',function(){
imagen.end();
console.log('File written');
});
}).listen(8082);
サーバーに問題があることはわかっていますが、.jpgファイルを書き込むためにこれと異なるものは見つかりません。