Upload a file using PhoneGap

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Get image handle
var largeImage = document.getElementById(‘id-of-your-image’); //or uri path from a library or taken camera pic
// Show the captured photo
// The inline CSS rules are used to resize the image
largeImage.src = imageURI;
var options = new FileUploadOptions();
options.fileKey=“file”;
//options.fileName=”your-wished-filename.ext”;
options.mimeType=“image/jpeg”;
var params = new Object();
params.value1 = “testing”;
params.value2 = “param”;
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, “http://yourdomain.com/upload.php”, win, fail, options);
// Make sure you use your own site!
 
// Success reporting
function win(r) {
alert(“Code = “ + r.responseCode);
alert(“Response = “ + r.response);
}
// Error reporting
function fail(message) {
alert(‘Failed because: ‘ + message);
}