私のアプリでは、コントローラーで sencha touch 2 と Phonegap 1.4 を使用し、写真撮影ボタン ハンドラーを使用しています。
onTakePhotoButton: function(){
// 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.CAMERA //or PHOTOLIBRARY
}
);
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey = "file";
var imagefilename = Number(new Date()) + ".jpg";
options.fileName = imagefilename;
options.mimeType = "image/jpeg";
options.chunkedMode = false;
var params = new Object();
params.image = imagefilename;
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI,your_request_upload_url_on_server, win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
var json_obj = Ext.decode(r.response);//remote server funciton upload return json type
if(json_obj!=null && json_obj.response.image_name!=null){
console.log(json_obj.response.image_name);
imageDisplay.setSrc(your_image_root_tmp+json_obj.response.image_name+'?dc='+Number(new Date()));
}else{
Ext.Msg.alert('Errors', "The server response failure!");
}
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
}
}
ここで詳細を参照できますhttp://zacvineyard.com/blog/2011/03/upload-a-file-to-a-remote-server-with-phonegap