【发布时间】:2019-01-31 06:04:03
【问题描述】:
我正在尝试在 Ionic 3 应用程序中返回一个用于 Firebase 存储上传的 blob。在 iOS 模拟器中(尚未在 iPhone 上测试)它可以工作,但在为 Android 构建并在手机上运行后,它返回“加载错误”。知道为什么会这样吗?
loadXHR(url) {
return new Promise(function (resolve, reject) {
try {
var xhr = new XMLHttpRequest()
xhr.open("GET", url)
xhr.responseType = "blob"
xhr.onerror = function () { reject("Network error.") }
xhr.onload = function () {
if (xhr.status === 200) { resolve(xhr.response) }
else { reject("Loading error:" + xhr.statusText) }
}
xhr.send()
}
catch (err) { reject(err.message) }
})
}
文件 url 用于使用 Ionic 的相机插件从手机图库中选择的图像,然后裁剪。
file:///storage/emulated/0/Android/data/io.app.events/cache/1535133947691-cropped.jpg
【问题讨论】:
标签: javascript angular ionic-framework xmlhttprequest firebase-storage