我正在尝试访问 Android系统的photolibrary来检索图像.我有navigator.camera.getPicture函数提供的imageURI变量.那是好的,直到那时.但后来,我想访问photolibrary并获取此图像的base64代码. 由于navigator.
由于navigator.camera.getPicture不可能返回两个数据(imageURI和imageData),我需要稍后获取base64信息.这是我试图使用的代码,查看phoneGap的“文件”文档,但它不起作用.
它停在“fileSystem.root.getFile”调用 – (错误回调中的错误:File4 = TypeError:表达式’evt.target'[undefined]的结果不是对象.在file:/// android_asset / www / phonegap- 1.3.0.js:717)
谁能帮帮我?谢谢.
function base64(imageURI) {
alert(imageURI);
document.addEventListener("deviceready", onDeviceReady);
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);}
function gotFS(fileSystem) {
alert("filesystem");
//Next line causes error. Perhaps imageURI is not a valid path?
fileSystem.root.getFile(**imageURI**, null, gotFileEntry, fail);}
function gotFileEntry(fileEntry) {
alert("gotfileentry");
fileEntry.file(gotFile, fail);}
function gotFile(file){
alert("got file");
readDataUrl(file);}
function readDataUrl(file) {
alert("readDataURL");
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
alert(evt.target.result);
};
reader.readAsDataURL(file);
}
function fail(evt) {
console.log(evt.target.error.code);}}
好的,第一个问题是失败函数返回的对象没有您尝试访问的属性.要查看错误对象中的内容,请尝试以下操作:
function fail(evt) {
alert("there was an error: " + JSON.stringify(evt));
}
让我们知道它产生了什么……
