# Upload Camera Images To Firebase Storage Using Ionic

**URL:** <https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795>\
**Category:** tutorials\
**Created:** [August 7, 2016, 5:14pm UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795 "2016-08-07T17:14:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronksaunders](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/aaronksaunders/32/13729_2.png) [@aaronksaunders](https://forum.ionicframework.com/u/aaronksaunders)\
**Post date:** [August 7, 2016, 5:14pm UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/1 "2016-08-07T17:14:16Z")

</div>

I have created a set of videos showing how to upload images to Firebase3 Storage using the Camera plugin and also using the Image Picker Plugin.

These examples save the images in firebase storage and not converting it to a base64 string

These examples show how it works with Ionic version 1 and ionic version 2

* * *

## **Version 1 Source Code and Video**

> **[aaronksaunders/firebaseStorageApp](https://github.com/aaronksaunders/firebaseStorageApp)**
>
> firebaseStorageApp - Source Code From YouTube Video on IonicFramework and Firebase Storage

[https://youtu.be/Z1F-0PnLgb8](https://youtu.be/Z1F-0PnLgb8)  
[https://youtu.be/2bDBwmyifGI](https://youtu.be/2bDBwmyifGI)

* * *

**Version 2 using Angular2 Source Code and Video**

* * *

> **[aaronksaunders/firebaseStorage2](https://github.com/aaronksaunders/firebaseStorage2)**
>
> firebaseStorage2 - source code for youtube video on Ionic2 & Firebase Image Upload

---

<div class="post-metadata">

**Author:** ![Notjameson](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@Notjameson](https://forum.ionicframework.com/u/Notjameson)\
**Post date:** [August 11, 2016, 2:44pm UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/2 "2016-08-11T14:44:14Z")

</div>

Hey, just wanted to comment and say thanks for this - totally unstuck me from a huge problem.

---

<div class="post-metadata">

**Author:** ![aaronksaunders](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/aaronksaunders/32/13729_2.png) [@aaronksaunders](https://forum.ionicframework.com/u/aaronksaunders)\
**Post date:** [August 22, 2016, 2:39am UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/3 "2016-08-22T02:39:33Z")

</div>

glad i could help out

---

<div class="post-metadata">

**Author:** ![aaronksaunders](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/aaronksaunders/32/13729_2.png) [@aaronksaunders](https://forum.ionicframework.com/u/aaronksaunders)\
**Post date:** [January 30, 2017, 2:10pm UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/4 "2017-01-30T14:10:18Z")

</div>

Updated to latest Ionic Release

> **[aaronksaunders/firebaseStorage2](https://github.com/aaronksaunders/firebaseStorage2)**
>
> firebaseStorage2 - source code for youtube video on Ionic2 & Firebase Image Upload

---

<div class="post-metadata">

**Author:** ![ehjaysonh](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ehjaysonh](https://forum.ionicframework.com/u/ehjaysonh)\
**Post date:** [March 8, 2017, 2:29pm UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/5 "2017-03-08T14:29:19Z")

</div>

Aaron, I am getting a TypeError from the $cordovaFile.readAsArrayBuffer code. Can you help me figure out the issue please?

$scope.addBusinessImage = function () {  
var options = {  
maximumImagesCount: 1, // only pick one image  
width: 800,  
height: 800,  
quality: 80  
};

```
  var fileName, path;

  $cordovaImagePicker.getPictures(options)
    .then(function (results) {
      console.log('Image URI: ' + results[0]);

      // lets read the image into an array buffer..
      // see documentation:
      // http://ngcordova.com/docs/plugins/file/
      fileName = results[0].replace(/^.*[\\\/]/, '');

      // modify the image path when on Android
      if ($ionicPlatform.is("android")) {
        path = cordova.file.cacheDirectory
      } else {
        path = cordova.file.tempDirectory
      }
	  
	
$cordovaFile.readAsArrayBuffer(path, fileName).then(function (success) {		
    // success
	
	var imageBlob = new Blob([success], { type: "image/jpeg" });
	  
	   var storageRef = firebase.storage().ref();

     // pass in the _filename, and save the _imageBlob
     storageRef.child('images/' + fileName).put(imageBlob).then(function(snapshot) {
		$ionicPopup.alert({
			title: 'Success Result',
			template: snapshot
		});
	 });

  }, function (error) {
    // error
	$ionicPopup.alert({
		title: 'Error Result',
		template: error + " - " + error.message
	});
 });
	  
  });

	  };
```

---

<div class="post-metadata">

**Author:** ![aaronksaunders](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/aaronksaunders/32/13729_2.png) [@aaronksaunders](https://forum.ionicframework.com/u/aaronksaunders)\
**Post date:** [March 18, 2017, 2:45am UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/6 "2017-03-18T02:45:09Z")

</div>

sorry, been out of pocket at sxsw, did you get this resolved?

---

<div class="post-metadata">

**Author:** ![ehjaysonh](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ehjaysonh](https://forum.ionicframework.com/u/ehjaysonh)\
**Post date:** [March 20, 2017, 4:03am UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/7 "2017-03-20T04:03:50Z")

</div>

Aaron,

No problem. It turns out my issue was just the platform. I was testing on ionic view and didn’t realize that the plugin was not supported.

Thanks for your help.

Best regards,  
Ehjayson Henry  
Phone: 404-713-8881

---

<div class="post-metadata">

**Author:** ![alkahtani](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@alkahtani](https://forum.ionicframework.com/u/alkahtani)\
**Post date:** [April 3, 2017, 8:28am UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/8 "2017-04-03T08:28:57Z")

</div>

Hello Aron,

i have tried everything i can but still not able to get the code working for uploading images to firebase storage from my ionic 1 app , got this error FileError {code: 1, message: “NOT\_FOUND\_ERR”}  
, here is the code exactly from your github repo 🙂`$scope.getPhoto=function () {

```
  var fileName, path;
  //loadData();
  var options = {
     quality: 80,
    destinationType: Camera.DestinationType.FILE_URI,
    sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
    allowEdit: true,
    encodingType: Camera.EncodingType.JPEG,
    popoverOptions: CameraPopoverOptions,
    saveToPhotoAlbum: false,
    correctOrientation: true,
    targetWidth :90,
    targetHeight :90
  };

  $cordovaCamera.getPicture(options)
    .then(function (results) {
      console.log('Image URI: ' + results[0]);
      // lets read the image into an array buffer..
      // see documentation:
      // http://ngcordova.com/docs/plugins/file/
      fileName = results[0].replace(/^.*[\\\/]/, '');

      // modify the image path when on Android
      if ($ionicPlatform.is("android")) {
       path = cordova.file.cacheDirectory
      } else {
        path = cordova.file.tempDirectory
      }
      alert(fileName)
      alert(path)
      return $cordovaFile.readAsArrayBuffer(path, fileName);
      
    }).then(function (success) {
      // success - get blob data
      var imageBlob = new Blob([success], { type: "image/jpeg" });
      // missed some params... NOW it is a promise!!
      alert ("before saveToFirebase method")
      return saveToFirebase(imageBlob, fileName);
      alert ("saveToFirebase method")

    }).then(function (_responseSnapshot) {
      // we have the information on the image we saved, now 
      // let's save it in the realtime database
      alert("beforesaveref")
      return saveReferenceInDatabase(_responseSnapshot)
      alert("saveref")
    }).then(function (_response) {
      alert("Saved Successfully!!")
    }, function (error) {
      // error
      alert(JSON.stringify(error))
      console.log(error)
    });
}

```

, can you please help me out with this issue.`

---

<div class="post-metadata">

**Author:** ![ankitkaushik](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ankitkaushik/32/108822_2.png) [@ankitkaushik](https://forum.ionicframework.com/u/ankitkaushik)\
**Post date:** [August 6, 2017, 3:33am UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/9 "2017-08-06T03:33:04Z")

</div>

Experts,

Can some please suggest the method to use in case i want to upload multiple photos from photo gallery in one go?

Cheers  
Ankit

---

<div class="post-metadata">

**Author:** ![saeed\_monis](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@saeed\_monis](https://forum.ionicframework.com/u/saeed_monis)\
**Post date:** [September 9, 2017, 3:52am UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/10 "2017-09-09T03:52:24Z")

</div>

can you tell me if i have to upload image along with some data and retrieve image with data

---

<div class="post-metadata">

**Author:** ![jaydz](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jaydz](https://forum.ionicframework.com/u/jaydz)\
**Post date:** [September 9, 2017, 6:17am UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/11 "2017-09-09T06:17:10Z")

</div>

Are you using firebase.storage? Firebase database only allows for references to URL paths I believe

---

<div class="post-metadata">

**Author:** ![aaronksaunders](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/aaronksaunders/32/13729_2.png) [@aaronksaunders](https://forum.ionicframework.com/u/aaronksaunders)\
**Post date:** [October 5, 2018, 2:45am UTC](https://forum.ionicframework.com/t/upload-camera-images-to-firebase-storage-using-ionic/59795/12 "2018-10-05T02:45:31Z")

</div>

> **[aaronksaunders/ionic4-firebase-storage](https://github.com/aaronksaunders/ionic4-firebase-storage)**
>
> File Upload from Ionic v4 App to Firebase Cloud Storage - aaronksaunders/ionic4-firebase-storage
