-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.js
46 lines (40 loc) · 1.33 KB
/
temp.js
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
35
36
37
38
39
40
41
42
43
44
45
46
var loaded = false;
var currentPhoto = null;
function onPhotosLoad() {
// only load the camera selector on first load if (!loaded) {
navigator.camera.getPicture(onPhotoLoadSuccess, onFail, {
quality: 50,
encodingType: Camera.EncodingType.PNG,
destinationType: navigator.camera.DestinationType.FILE_URI
});
loaded = true;
}
}
function onPhotoLoadSuccess(photoUri) {
// store current photo for saving later currentPhoto = photoUri;
document.getElementById('photo').src = photoUri;
}
function onFail(message) {
alert('Failed because: ' + message);
}
function savePhoto() {
if (currentPhoto == null) {
alert("Please select a photo first");
return;
}
var uploadOptions = new FileUploadOptions();
uploadOptions.fileKey = "file";
uploadOptions.fileName =
currentPhoto.substr(currentPhoto.lastIndexOf('/') + 1);
uploadOptions.mimeType = "image/png";
var fileTransfer = new FileTransfer();
// Be sure to update the URL below to your site fileTransfer.upload(currentPhoto,
"http://www.webistrate.com/phonegap/upload.php", uploadSuccess, uploadFail, uploadOptions);
}
function uploadSuccess(result) {
alert("Successfully transferred " +
result.bytesSent + "bytes");
}
function uploadFail(error) {
alert("Error uploading file: " + error.code);
}