【发布时间】:2016-12-03 07:25:20
【问题描述】:
我已经标记了一些关于该主题的主题(例如:Uploading image to Firebase Storage from Cordova app)但没有找到我的答案...
我正在开发一个 IONIC 项目,该项目使用 ngCordova 相机插件来拍照并从库中获取图片。
所以我得到了一个图像 URI 的结果,我想将它上传到 Firebase 存储中(作为文件或 Blob)。 这是我的代码:
$scope.fromCamera = function() {
$ionicPlatform.ready(function() {
var options = {
quality: 75,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
saveToPhotoAlbum: true e
};
$cordovaCamera.getPicture(options).then(function(imageURI) {
window.resolveLocalFileSystemURL(imageURI, function (fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function () {
// This blob object can be saved to firebase
var blob = new Blob([new Uint8Array(this.result)], { type: "image/jpeg" });
// Create the storage ref
var ref = storageRef.child('images/test');
// Upload the file
uploadPhoto(blob, ref);
};
reader.readAsArrayBuffer(file);
});
}, function (error) {
console.log(error)
});
});
});
};
我读取文件并将其转换为 Blob,然后再将其上传到 Firebase。我收到一个“编码错误”,告诉我“提供给 API 的 URI 格式不正确,或者生成的数据 URL 超出了数据 URL 的 URL 长度限制。”
我正在使用带有 Cordova Mocks 扩展的 chrome 浏览器运行它。
欢迎任何帮助! 谢谢
【问题讨论】:
-
uploadPhoto中有什么内容? -
@Aaron Saunders,我的函数 uploadPhoto() 在这里!谢谢您的关注! :)
标签: ionic-framework firebase cordova-plugins ngcordova firebase-storage