0

我面临从相机和画廊上传文件的问题。

从图库中选择几张图片时,我能够成功地将图片上传到 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);
}

请帮助我确定我做错了什么。

4

2 回答 2

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你的文件大小在哪里。

于 2013-05-17T04:48:27.167 回答
1

这对我有用。

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

<standardEndpoint name="" 
    helpEnabled="true" 
    automaticFormatSelectionEnabled="true" 
    maxBufferSize="2147483647" 
    maxReceivedMessageSize="2147483647"> 
</standardEndpoint> 
于 2013-06-27T08:02:31.573 回答