Balu
Balu

Reputation: 607

upload images or videos to remote server using phonegap

I am doing project in android phonegap.Here I want to upload images and videos to remote server. I used the following link. http://zacvineyard.com/blog/2011/03/upload-a-file-to-a-remote-server-with-phonegap

I also change some options like options.chunkedMode = false ,android:debuggable="true" and . But still it shows error code 3.I am using the cordova-2.0.0.js version.Can anyone suggest some answer.

My js code is

    **

<script type="text/javascript" charset="utf-8">

            // Wait for PhoneGap to load
    document.addEventListener("deviceready", onDeviceReady, false);

            // PhoneGap is ready
    function onDeviceReady() {
      // Do cool things here...
            }

    function getImage() {

                // Retrieve image file location from specified source
                navigator.camera.getPicture(uploadPhoto, function(message) {
                alert('get picture failed');
                },
                {quality: 50,
                destinationType: navigator.camera.DestinationType.FILE_URI,
                sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
                }
                );
    }

    function uploadPhoto(imageURI) {

                var options = new FileUploadOptions();
                options.fileKey="file";
                options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
                options.mimeType="image/jpeg";

                var params = new Object();
                params.value1 = "test";
                params.value2 = "param";

                options.params = params;
                options.chunkedMode = false;

                var ft = new FileTransfer();
                ft.upload(imageURI, "url of ther server/upload.php", win, fail, options, true);
                console.log("H");
    }

    function win(r) {
                console.log("HIIIIIiiii");
                console.log("Code = " + r.responseCode);
                console.log("Response = " + r.response);
                console.log("Sent = " + r.bytesSent);
                alert(r.response);
    }

    function fail(error) {
                alert("There is something");
                alert("An error has occurred: Code = " + error.code);
    }

    </script>

**

and my php code is

<?php

print_r($_FILES);
$new_image_name = "namethisimage.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/".$new_image_name);

?>

Thanks.

Upvotes: 1

Views: 4275

Answers (1)

Ian Devlin
Ian Devlin

Reputation: 18870

Have you added the URL in question to your whitelist?

e.g. in config.xml do you have something like:

<access origin="www.myurl.com" subdomains="true" />

or

<access origin="*" />

which allows all URLs.

Error code 3 is a FileTransferError.CONNECTION_ERR by the way.

Upvotes: 1

Related Questions