【发布时间】:2016-12-06 20:04:30
【问题描述】:
我正在努力将图像从 Ionic 应用中的 ngCordova 相机插件上传到 Firebase 存储中。
我不能使用 fileTransfert 插件,因为没有带有 firebase 存储的数据库 url(除非我错了......)而且我只能存储文件。
您对如何执行此操作有一些想法吗?
这是我目前使用cordova文件在blob中读取和转换的代码:
$scope.fromLibrairy = function() {
$ionicPlatform.ready(function() {
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
targetWidth: 300,
targetHeight: 300,
};
$cordovaCamera.getPicture(options).then(function(imageURI) {
$scope.imgURI = imageURI;
var name = imageURI.substring(imageURI.lastIndexOf('/')+1, imageURI.length);
var directory = imageURI.substring(0, imageURI.lastIndexOf('/')+1);
$cordovaFile.readAsArrayBuffer(directory, name).then(function(success) {
alert(success);
var blob = new Blob([success], { type:"image/jpeg" });
// Create the storage ref
var ref = storageRef.child('images/' + name);
// My function to upload in firebase storage (it works with jpeg)
$scope.uploadPhoto(blob, ref);
}, function (error) {
alert("erreur du readAsArrayBuffer" + error + error.code);
})
}, function(error){
alert('erreur du getPicture' + error);
});
});
};
任何帮助将不胜感激! :)
【问题讨论】:
标签: cordova ionic-framework firebase cordova-plugins firebase-storage