我的 FileReader 对象可以完美上传图像。我正在追踪onload
以及其他事件,这些都在我上传图像时发生:
fileReader = new FileReader();
fileReader.onloadstart = (e) => {
window.alert('fileReader onloadstart');
window.alert(e);
};
// ... and the same for onprogress, onabort, onerror, then finally:
fileReader.onload = (e) => {
window.alert('arrived to fileReader.onload!');
// ...
};
I added cordova-plugin-media-capture
捕获音频。我现在需要使用现有的fileReader.onload
回调上传等
但无论我做什么,我都无法得到fileReader.readAsDataURL
回复。下面是我的代码改编自这个答案 https://stackoverflow.com/questions/29192327/get-base64-of-audio-data-from-cordova-capture关于类似的问题,但它没有解决它。
没有任何一个fileReader
事件正在触发,甚至没有错误。这fileReader.readAsDataURL
函数可用,但是当调用它时,发生的一切是屏幕短暂变白,然后我回到之前所在的页面,就好像我什么也没做一样。上面的方法都没有fileReader
显示他们的警报。
navigator.device.capture.captureAudio((files) => {
const file = files[0];
newFile = new File(
file.name,
file.localURL,
file.type,
file.lastModifiedDate,
file.size);
window.alert(newFile);
// --> [Object object]
window.alert(JSON.stringify(newFile));
// --> An object with name, localURL etc. See image.
window.alert(fileReader.readAsDataURL);
// --> function readAsDataURL() { [native code] }
fileReader.readAsDataURL(newFile); // nothing at all
})
弦化的newFile
对象是:
我尝试过处理该文件captureAudio
以不同的方式给出:
-
resolveLocalFileSystemURL
: https://ourcodeworld.com/articles/read/80/how-to-convert-a-image-from-the-device-to-base64-with-javascript-in-cordova https://ourcodeworld.com/articles/read/80/how-to-convert-a-image-from-the-device-to-base64-with-javascript-in-cordova
-
fileSystem.root.getFile
as in https://groups.google.com/forum/#!msg/phonegap/uX_aDRKp72I/ZUbt0ThWVQkJ https://groups.google.com/forum/#!msg/phonegap/uX_aDRKp72I/ZUbt0ThWVQkJ
但每次都是同样的事情:当我到达readAsDataURL
,什么都没有发生了。可能出什么问题了?
编辑:我忘了提及一些事情:
- 在 iOS 设备和模拟器上测试
- 科尔多瓦插件文件已安装