我正在尝试访问
Android系统的photolibrary来检索图像.我有navigator.camera.getPicture函数提供的imageURI变量.那是好的,直到那时.但后来,我想访问photolibrary并获取此图像的base64代码.
由于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,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);}}
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。