【问题标题】:upload image using PhoneGap to .NET WCF Rest Service使用 PhoneGap 将图像上传到 .NET WCF Rest Service
【发布时间】:2013-05-01 12:04:51
【问题描述】:

我在从相机和画廊上传文件时遇到问题。

从图库中选择几张图片时,我能够成功地将图片上传到 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,感谢您的回复。没有权限问题。它似乎是 WCF 服务的问题。其接受文件小于 65 KB,这是解决增加 WCF 请求值问题后默认最大请求大小的问题
  • 你有你的WCF服务的代码吗?我遇到了无法从 cordova 文件传输中上传图像的问题?

标签: wcf cordova wcf-rest


【解决方案1】:

这对我有用。

问题出在 WCF 服务上。其接受的文件小于 65 KB,增加maxReceivedMessageSizevalue 后默认为最大请求大小问题已解决。

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

【讨论】:

    【解决方案2】:

    您的 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 是您的文件大小。

    【讨论】:

      猜你喜欢
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-10
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 2013-04-28
      相关资源
      最近更新 更多