我正面臨從相機和圖庫中上傳文件的問題。使用PhoneGap將圖像上傳到.NET WCF Rest服務
從圖庫中選擇幾張圖片時,我能夠成功上傳圖片到WCF服務。因此,WCF服務工作正常,上傳文件的代碼也是如此,同樣的代碼也適用於模擬網絡攝像頭。
但是從圖片庫中選取一些圖片時,我得到* 錯誤代碼*
java.io.FileNotFoundException: http://www.foobar.com/sasas
JavaScript代碼
function selectImageFromCamera(){
var popover = new CameraPopoverOptions(300,300,100,100,Camera.PopoverArrowDirection.ARROW_ANY);
var options = { quality: 49, destinationType: Camera.DestinationType.FILE_URI,sourceType: Camera.PictureSourceType.CAMERA, popoverOptions : popover};
navigator.camera.getPicture(this.uploadPhoto, this.onFail, options);
}
function selectImageFromGallery(){
var popover = new CameraPopoverOptions(300,300,100,100,Camera.PopoverArrowDirection.ARROW_ANY);
var options = { quality: 49, destinationType: Camera.DestinationType.FILE_URI,sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, popoverOptions : popover};
navigator.camera.getPicture(this.uploadPhoto, this.onFail, options);
}
function uploadPhoto(imageURI) {
var serverUrl = "http://www.foobar.com/safafa";
var image = document.getElementById("imgUpload");
image.style.display = "block";
image.src = imageURI;
var fileUploadOptions = new FileUploadOptions();
fileUploadOptions.fileKey="file";
fileUploadOptions.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
fileUploadOptions.mimeType="image/png";
fileUploadOptions.chunkedMode=true;
var ft = new FileTransfer();
ft.upload(imageURI, serverUrl, this.win, this.fail, fileUploadOptions);
}
請幫我找出我在做什麼錯誤。
您是否已檢查權限設置?也許不允許訪問文件。 – Mario 2013-05-15 05:26:30
@Mario,謝謝你的回覆。沒有權限問題。它似乎是WCF服務的問題。它接受的文件小於65 KB,這是在增加WCF請求值問題之後默認情況下的最大請求大小 – Satpal 2013-05-15 11:16:01
您恰好擁有WCF服務的代碼?我遇到無法從cordova文件傳輸上傳圖像的問題? – sioesi 2016-10-13 22:00:42