Satpal
Satpal

Reputation: 133423

upload image using PhoneGap to .NET WCF Rest Service

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.

Upvotes: 0

Views: 2328

Answers (2)

Satpal
Satpal

Reputation: 133423

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> 

Upvotes: 1

Ayush
Ayush

Reputation: 3999

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.

Upvotes: 4

Related Questions