[英]upload an image from android app to the server
我嘗試將圖像從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);
}
}
嘗試使用:
options.mimeType = "multipart/form-data";
並嘗試設置一些參數。 我正在發布適合我的示例代碼:
var imageFile=$("#largeImage").attr('src');
if(imageFile=="")
alert("No image to upload.");
else{
var ft,options;
options = new FileUploadOptions();
options.fileKey = "profile_image";
options.fileName=name;
options.mimeType = "multipart/form-data";
params = {
val1: "some value",
val2: "some other value"
};
options.params = params;
ft = new FileTransfer();
ft.upload(imageFile, uploadUrl, success, fail, options);
}
}
我正在使用Java Servlet處理上傳的圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.