i'm struggling upload images firebase storage ngcordova camera plugin in ionic app.
i can't use filetransfert plugin cause there no database url firebase storage (unless i'm wrong...) , can store file.
do have ideas on how perform that?
here code @ moment using cordova file read , converting in 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 storage ref var ref = storageref.child('images/' + name); // function upload in firebase storage (it works jpeg) $scope.uploadphoto(blob, ref); }, function (error) { alert("erreur du readasarraybuffer" + error + error.code); }) }, function(error){ alert('erreur du getpicture' + error); }); }); };
any appreciated! :)
try this...
var name = imageuri.replace(/^.*[\\\/]/, ''); var directory = cordova.file.tempdirectory;
make sure have $cordovafile
plugin installed , ng-cordova configured properly.
please include specific error log information
otherwise complete solution here similar question - https://stackoverflow.com/a/38708624/122313
Comments
Post a Comment