Android + phoneGap Upload a File error code 3

1,534 views
Skip to first unread message

u me

unread,
May 8, 2013, 7:39:59 AM5/8/13
to phon...@googlegroups.com


 
Hi,

i am going through this sample example link.

Upload a File to a Remote Server with PhoneGap

http://zacvineyard.com/blog/2011/03/upload-a-file-to-a-remote-server-with-phonegap

But when i hit to local server this throws file upload error code 3

This is my code :-

<!DOCTYPE HTML>
<html>
<head>
<title>File Transfer Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<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, "http://yourdomain.com/upload.php", win, fail, options)


// when i use this URL file is NOT uploading show error code 3
ft.upload(imageURI, "http://10.0.0.2/mobile/upload.php", win, fail, options);


// when i use this URL file is uploading successfully But i am not getting file in that location
ft.upload(imageURI, "http://192.9.200.164:8080/bdmbs/uploads/upload.php", win, fail, options);

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

alert(r.response);
}
function fail(error) {
alert("An error has occurred: Code = " = error.code);
}
</script>
</head>
<body>
<button onclick="getImage();">Upload a Photo</button>
</body>
</html>

upload.php file code

<?php
print_r($_FILES);
$new_image_name = "namethisimage.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "/srv/www/upload/".$new_image_name);
?>

how to set system path
"/srv/www/upload/" my path C:\upload/


and request is hitting to server http://192.9.200.164:8080/bdmbs/uploads/upload.php and the message show file sent success.

i need to set the location where images are save ?


包四維

unread,
Jul 31, 2013, 11:09:18 AM7/31/13
to phon...@googlegroups.com
You must use an absolute path instead of a relative path
Otherwise, the program simply do not understand

u me於 2013年5月8日星期三UTC+8下午7時39分59秒寫道:

Сергей Цыбульский

unread,
Oct 9, 2013, 5:30:44 AM10/9/13
to phon...@googlegroups.com
Guys try this - add code:
var op;
op = new FileUploadOptions();

op.headers = {
Connection: "close"
};

After adding this - code started to work well with no errors.
Hope that helps!

среда, 8 мая 2013 г., 14:39:59 UTC+3 пользователь u me написал:

Idan Shechter

unread,
Mar 19, 2014, 7:14:58 AM3/19/14
to phon...@googlegroups.com
Doesn't work for me with Cordova 3.2 and on Android 4.3, get Code 3 error.

Arut Selvan

unread,
May 8, 2014, 3:36:30 AM5/8/14
to phon...@googlegroups.com
I am facing tha same issue any suggestions.

Ömer Alper Özkan

unread,
May 18, 2015, 4:37:40 PM5/18/15
to phon...@googlegroups.com

How could you handle this problem? 

Connection: "close" doesn't work for me, chunkedMode = false; also doesn't work. I use absolute url path, i couldn't get around the problem. I use phonegap developer app instead of emulators, can it cause such problems? Anyone has any idea?

 

Jesse Monroy

unread,
May 18, 2015, 7:28:39 PM5/18/15
to phon...@googlegroups.com
Ömer,
the post your responded to is over one year old.

Jesse
Reply all
Reply to author
Forward
0 new messages