0

I am facing problem upload file from camera and gallery.

When selecting few images from gallery I am able to successfully upload the image to WCF service. Thus WCF service is working fine and so is the code to upload file and also same code works with emulated web camera also.

However when selecting a few images from gallery I am getting *error code *

java.io.FileNotFoundException: http://www.foobar.com/sasas

JavaScript Code

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);
}

Please help me to identify What I am doing wrong.

Satpal
  • 132,252
  • 13
  • 159
  • 168
  • Have you checked the permission settings? Maybe access to files is not allowed. – Mario May 15 '13 at 05:26
  • @Mario, thanks for you reply. Not issue with permission. Its seems to be issue with the WCF service. Its accepting file less than 65 KB, which is max request size by default after incresing WCF request value problem is solved – Satpal May 15 '13 at 11:16
  • You happen to have the code of your WCF service? I'm having the problem of not being able to upload images from cordova file transfer? – sioesi Oct 13 '16 at 22:00

2 Answers2

4

Your PhoneGap code seems to be all right but just check your WCF Service web.config File.

You'll want something like this to increase the file size.

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

where 100000000 is your file size.

Ayush
  • 3,989
  • 1
  • 26
  • 34
1

This worked for me.

The issue was with the WCF service. Its accepted file less than 65 KB, which is max request size by default after increasing maxReceivedMessageSizevalue problem was solved.

<standardEndpoint name="" 
    helpEnabled="true" 
    automaticFormatSelectionEnabled="true" 
    maxBufferSize="2147483647" 
    maxReceivedMessageSize="2147483647"> 
</standardEndpoint> 
Satpal
  • 132,252
  • 13
  • 159
  • 168