Upload image base 64 to Firebase

0

Hello,

I'm trying to upload images in base64 to the firebase, but I'm getting the following error. I tried to follow the Firebase tutorial on the official website and one found here on the stack itself, but I still get the same error.

  

{code: "storage / invalid-format", message: "Firebase Storage: String   does not match format 'base64': Invalid character found ",   serverResponse: null, name: "FirebaseError"}

$scope.upload = function (dataUrl, name) {
var image = dataUrl;
  uploadTask = firebase.storage().ref('profileImg',  loggedUserSrvc.getUser().uid).child('profileImg').putString(image, 'base64', {contentType:'image/jpg'});

	uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'
	  function(snapshot) {
		// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
		var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
		console.log('Upload is ' + progress + '% done');
		switch (snapshot.state) {
		  case firebase.storage.TaskState.PAUSED: // or 'paused'
			console.log('Upload is paused');
			break;
		  case firebase.storage.TaskState.RUNNING: // or 'running'
			console.log('Upload is running');
			break;
		}
	  }, function(error) {
		console.log(error);
	}, function() {
	  // Upload completed successfully, now we can get the download URL
	  var downloadURL = uploadTask.snapshot.downloadURL;
	});

}
<div class="card">
	<button  ng-click="upload(croppedDataUrl, picFile.name)" class="button button-balanced button-block">
		Salvar
	</button>
</div>
    
asked by anonymous 29.09.2017 / 14:17

1 answer

1

If you are using the camera with ionic, there is a list of preferences that you must configure before (CameraOptions), here you will find the documentation: link

In these preferences you should put:

destinationType: DATA_URL

After this, your camera will be returning the photo already in base64

    
08.12.2017 / 21:31