我尝试将图像从 android 应用程序上传到服务器。我正在使用 HTML5 和电话间隙。我正在使用 WCF 将图像从 android 应用程序发送到远程服务器。当我尝试使用我的应用上传时,它会上传一个文件,但文件的大小为 0,所以里面没有任何内容。(我的 WCF 工作正常,只是我知道问题出在我的 android 应用程序上)
这是我的上传代码:
function uploadPicture() {
// Get URI of picture to upload
var img = document.getElementById('camera_image');
var imageURI = img.src;
if (!imageURI || (img.style.display == "none")) {
document.getElementById('camera_status').innerHTML = "Take picture or select picture from library first.";
return;
}
// Verify server has been entered
server = document.getElementById('serverUrl').value;
if (server) {
// Specify transfer options
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.chunkedMode = false;
// Transfer picture to server
var ft = new FileTransfer();
ft.upload(imageURI, server, function(r) {
document.getElementById('camera_status').innerHTML = "Upload successful: " + r.bytesSent + " bytes uploaded.";
}, function(error) { document.getElementById('camera_status').innerHTML = "Upload failed: Code = " + error.code; },
options);
}
}