2013-05-07 72 views
0

我正面臨從相機和圖庫中上傳文件的問題。使用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); 
} 

請幫我找出我在做什麼錯誤。

+0

您是否已檢查權限設置?也許不允許訪問文件。 – Mario 2013-05-15 05:26:30

+0

@Mario,謝謝你的回覆。沒有權限問題。它似乎是WCF服務的問題。它接受的文件小於65 KB,這是在增加WCF請求值問題之後默認情況下的最大請求大小 – Satpal 2013-05-15 11:16:01

+0

您恰好擁有WCF服務的代碼?我遇到無法從cordova文件傳輸上傳圖像的問題? – sioesi 2016-10-13 22:00:42

回答

1

這對我有效。

問題出在WCF服務上。其接受的文件小於65 KB,這是在增加maxReceivedMessageSize值問題之後默認的最大請求大小。

<standardEndpoint name="" 
    helpEnabled="true" 
    automaticFormatSelectionEnabled="true" 
    maxBufferSize="2147483647" 
    maxReceivedMessageSize="2147483647"> 
</standardEndpoint> 
4

你的PhoneGap代碼似乎沒問題,但只是檢查你的WCF服務web.config文件。

你會想要這樣的東西來增加文件的大小。

<bindings> 
    <basicHttpBinding> 
     <binding name="basicHttp" allowCookies="true" 
       maxReceivedMessageSize="10000000" 
       maxBufferSize="10000000" 
       maxBufferPoolSize="10000000"> 
      <readerQuotas maxDepth="32" 
       maxArrayLength="100000000" 
       maxStringContentLength="100000000"/> 
     </binding> 
    </basicHttpBinding> 
</bindings> 

其中100000000是您的文件大小。

+0

它工作了嗎。 – Ayush 2013-05-17 04:53:28

相關問題