我使用下面的代码获取图像的base64数据显示并上传到服务器。 但我想将这个捕获的图像保存在SD卡文件夹中。请帮助我做到这一点。如何在PhoneGap的移动拍摄的图像文件夹中的SD卡
这对我来说需要获取base64图像数据,因为服务器只支持这种格式。这就是为什么我使用destinationType = 0(意味着DATA_URL)。我现在有base64图像数据,但是如何将这些数据保存到SD卡?
uploadPhoto(isSourceCamera, onPhotoDataSuccess, onFail);
function uploadPhoto(isSourceCamera, onPhotoDataSuccess, onFail)
{
pictureSource = navigator.camera.PictureSourceType;
if (isSourceCamera)
{
//QUALITY MUST BE LOW TO AVOID MEMORY ISSUES ON IPHONE4 ! (and other low memory phones).
//must resize to make it faster to upload and avoid failure with low memory phones.
navigator.camera.getPicture(onSuccessFunc, onFail, {
quality : 35,
sourceType : pictureSource.CAMERA,
targetWidth:750,
targetHeight:750,
allowEdit:true,
destinationType:0
});
}
else
{
navigator.camera.getPicture(onSuccessFunc, onFail, {
quality : 35,
sourceType : pictureSource.PHOTOLIBRARY,
targetWidth:750,
targetHeight:750,
allowEdit:true,
destinationType:0
});
}
}
function onPhotoDataSuccess(imageData)
{
**//I want to smae my image here in sdcard folder.**
var nodeid = localStorage.getItem("user_nodeid");
var modifyImgData = imageData.replace(' ', '+');
document.getElementById('image').src = setLocalStorageImage(localStorage.getItem(nodeid+"image"), modifyImgData);
document.getElementById('profileMenu').src = setLocalStorageImage(localStorage.getItem(nodeid+"smallimage"), modifyImgData);
$.ajax({
type: "POST",
url: appURL+"api/upload/image/" +nodeid+ "/1",
data: "image=" + encodeURIComponent(modifyImgData),
success: function(msg){
//No need to do anything here
if (msg.documentElement.getElementsByTagName("message")[0].childNodes[0].nodeValue != 'success')
onFail('Error in uploading image at server. Please try again.');
}
});
}
function onFail(message){
alert(message);
}
嗨西蒙 感谢您的回复,我想 “FileWriter的”,而不是在successed SD卡的perticular位置(如SD卡/ myphotos)保存。 如何分配此路径? 也不知道如何将base64数据保存为phonegap中的有效图像? 请帮忙.. – Ram 2012-03-30 07:30:50
以下是使用FileWriter的一个很好的例子。 http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html#FileWriter_full_example – 2012-04-02 20:54:41