Skip to content

Upload a photo to Firebase Storage with Image URI

I am currently attempting to upload a photo to my Firebase app’s storage in my Apache Cordova app. I currently get the photo’s URI with the following code:

function getPhotoFromAlbum() {, onFail, {
        quality: 50,

function onPhotoURISuccess(imageURI) {
    var image = document.getElementById('image'); = 'block';
    image.src = imageURI;



And then am attempting to convert the image into a file and push it to my Firebase storage with the following function:

function getFileEntry(imgUri) {
    window.resolveLocalFileSystemURL(imgUri, function success(fileEntry) {

        console.log("got file: " + fileEntry.fullPath);
        var filename = "test.jpg";
        var storageRef ='/images/' + filename);
        var uploadTask = storageRef.put(fileEntry);

    }, function () {
        // If don't get the FileEntry (which may happen when testing
        // on some emulators), copy to a new FileEntry.

I have both the file and the camera cordova plugins installed, the only errors I get when I attempt to do this is

Error in Success callbackId: File1733312835 : [object Object]

Which is just an error message from cordova.js

I also know I have my Firebase storage set up correctly because I have tested it through an emulator by adding a file input and successfully uploading whatever file the user added, to the Firebase storage.

Is it possible to upload a file to Firebase storage using this method of converting an image to a file through its URI, and then uploading it? If so, what is the correct way to do so / what is wrong with the way i’m doing it?



I was able to accomplish uploading an image by using a data url. Below is my code:

var filename = "test.jpg";
var storageRef ='/images/' + filename);

var message = 'data:image/jpg;base64,' + imageUri;
storageRef.putString(message, 'data_url').then(function (snapshot) {
  console.log('Uploaded a data_url string!');
User contributions licensed under: CC BY-SA
1 People found this is helpful