i’m trying to upload an get photo in my ionic 2 app. i succeed to run the camera and save the photo in firebase but not to get and display it on my app. i’m not sure i’m doing it right, the save in firebase. i put here my code.
add-note.ts
import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import { Camera } from ‘ionic-native’;
import {NotesData} from “…/…/providers/notes-data”;
note-data.ts //provider for notes to upload the photo to firebase
import { Injectable } from ‘@angular/core’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;
import firebase from ‘firebase’
/*
Generated class for the NotesData provider.
See Angular
for more info on providers and Angular 2 DI.
*/ @Injectable()
export class NotesData {
//user data
public currentUser: any;
public profilePictureRef: any;
//notedata
public notesList: any;
This is an example of how I upload pictures to firebase. Instead of pushing "data:image etc to the Database, I push it to storage, then grab the Storage link and push it to the database as seen in the “.then” promise, the URL is stored in “downloadURL”
I’m trying the same code:
In my constructor:
this.fireAuth = firebase.auth(); // We are creating an auth reference.
this.userProfile = firebase.database().ref(’/userProfile’);
this.profilePictureRef = firebase.storage().ref(’/userProfilePhoto/’);
but this doesn’t work. The image does not get uploaded to the corresponding firebase storage nor reaches the database. Could you please share your thoughts?
if you are getting any error .check that and post it.
i was getting invalid string error .
so done this.
[code]
let pic:Array;
pic=Array(2);
pic=picture.split(’,’);
// i used it to seperate invalid string with picture string
let msg:string;
msg=pic[1];
[/code]'
use that msg variable to pass in firebase
I modified some tutorials online so that it didnt require a user auth, here’s a repo https://github.com/Matt4759/Ionic3-FirebaseImageSharing.
Just plug your firebase creds into app.component, this puts it in storage under the title they input, and then displays that on the home page.