使用PhoneGap上传图像到.NET WCF Rest服务

时间:2013-05-07 13:45:39

标签: wcf cordova 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);
}

请帮我辨别我做错了什么。

2 个答案:

答案 0 :(得分: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是您的文件大小。

答案 1 :(得分:1)

这对我有用。

问题在于WCF服务。它接受的文件小于65 KB,在增加maxReceivedMessageSize值问题后默认为最大请求大小。

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