angularjs - Can't get url of image uploaded to firebase storage -
i new ionic, program takes picture , sent firebase. question is: how can show url of image in view? have controller:
i appreciate if can help, greetings
.controller("formctrl", function($scope,sharedutils,$ionicpopup,$state, $rootscope, $cordovacamera) { $scope.capturarfoto = function(sourcetype) { var options = { quality : 75, destinationtype : camera.destinationtype.file_uri, sourcetype : sourcetype, encodingtype: camera.encodingtype.jpeg, popoveroptions: camerapopoveroptions, targetwidth: 500, targetheight: 500, savetophotoalbum: false }; $cordovacamera.getpicture(options).then(function(imagedata) { // $scope.images = imagedata; var storageref = firebase.storage().ref(); // filename = imagedata.name; var getfileblob = function(url, cb) { var xhr = new xmlhttprequest(); xhr.open("get", url); xhr.responsetype = "blob"; xhr.addeventlistener('load', function() { cb(xhr.response); }); xhr.send(); }; var blobtofile = function(blob, name) { blob.lastmodifieddate = new date(); blob.name = name; return blob; }; var getfileobject = function(filepathorurl, cb) { getfileblob(filepathorurl, function(blob) { cb(blobtofile(blob, new date().gettime())); // segundo parametro es el nombre de imagen }); }; getfileobject(imagedata, function(fileobject) { var metadata = { 'contenttype': fileobject.type }; storageref.child('images/' + fileobject.name).put(fileobject, metadata); uploadtask.on('state_changed', null, function(error) { // [start onfailure] console.error('upload failed:', error); alert('upload failed:', error); // [end onfailure] }, function() { console.log('uploaded',uploadtask.snapshot.totalbytes,'bytes.'); console.log(uploadtask.snapshot.metadata); var url = uploadtask.snapshot.metadata.downloadurls[0]; console.log('file available at', url); // [start_exclude] document.getelementbyid('linkbox').innerhtml = '<img src="' + url + '">'; // [end_exclude] }); }); }, function(error) { console.error(error); alert(error); }); };
<ion-view style="" class=" " id="page8" title="enviar incidencia"> <ion-content class="has-header" padding="true" ng-controller="formctrl"> <button class="button button-full button-assertive" ng-click="capturarfoto()"> take photo </button> </ion-content> </ion-view>
fixed , working me:
before: uploadtask.on('state_changed', null, function(error) { after: var uploadtask = uploadtask.on('state_changed', null, function(error) {
:)
Comments
Post a Comment