I wrote a client for my server based on jquery mobile. I just cannot figure out how to transfer photos to my server because when I use GET method to post base64 strings, the server says the URI is too long.
So I tried to move the webpages and scripts to server and left a local file to redirect to server page. But right now, I can take photos but there seems have no callback when I finished.
Here is what I did
var imgTakePhotoStatusBase64="Wyk+HjAxHTAyNzg3MDUdODQwHTAxOR0wMDAwMDAwMDAwMDAwMDAdRkRFQh0wMDAwMDAwHTA0MB0dMS8xHTUwLjVMQh1OHVcgMzR0aCBTdHJlZXQdQXVzdGluHVRYHSAeMDYdMTBaR0QwMDQdMTFaUmVjaXBpZW50IENvbXBhbnkgTmFtZR0xMlo5MDEyNjM3OTA2HTE0WioqVEVTVCBMQUJFTCAtIERPIE5PVCBTSElQKiodMjNaTh0yMlocWR0yMFogHDAdMjZaNjEzMxwdHgQ=";
function TextStatus(){
var s=window.prompt("","请输入广播的内容");
if(s!=null&&s!=""){
SetStaus(s);
}
}
$("#pageTakePhotoStatus").live("pageshow", function() {
TakePhotoStatus()
});
function TakePhotoStatus(){
imageData="";
navigator.camera.getPicture(onTakePhotoStatusSuccess, onTakePhotoStatusFail, { quality: 75 });
}
function onTakePhotoStatusSuccess(imageData) {
var image = document.getElementById('imgTakePhotoStatus');
image.src = "data:image/jpeg;base64," + imageData;
imgTakePhotoStatusBase64=imageData;
}
function onTakePhotoStatusFail(message) {
alert('获取照片失败,因为: ' + message);
}
function TakePhotoStatusOk(){
try
{
var myDate = new Date();
var r=myDate.getTime();
var path="uploads.share/"+r+"/"+r+".jpg";
doMethod("ImageUploadByBase64String","{'str':'"+e(imgTakePhotoStatusBase64)+"','path':'"+e(path)+"'}",null,
function(result){
doMethod("PublishPhotoes","{'located':'false','path':'"+e(path)+"','text':'"+e("描述:"+$("#txaTakePhotoStatusDes").val())+"'}",null,
function(r){
alert("您的照片已经发布");
history.back();
});
});
}catch(err)
{
alert(err.description);
}
}
But onTakePhotoStatusSuccess doesn’t work when I take a photo. When I run it in local, it is just fine.
Camera works with phonegap, so if the user has your code running as an app it’s ok.
It won’t work as a webapp, because there’s no phonegap then.
Now the main issue:
POST might refuse to work cross-domain (not sure if phonegap can be set to allow it). If you can – use POST. If not, read:
GET can hold as much data as the browser is willing to send and the server is willing to catch. There is no standard. IE sends 2048 characters (2kb), FF sends over 100kb etc.
You have to test your server and maybe configure it to accept large GET queries.
Now the fun part – if you know the length of GET that is avaliable to you, you can transfer data in chunks.
Why not send and then confirm that it’s all done? Well, it’s asynchronous, so you never know.
This works. I did some different implementations of sending lots of data cross-domain with JSONP