on the firebase website there is
FirebaseStorage storage = FirebaseStorage.getInstance(“gs://my-custom-bucket”);
but i don’t think this is for ionic.
i wonder if there is a solution for this?
thanks
You should be able to get the reference with just something like
import firebase from 'firebase';
storageRef: firebase.storage.Reference;
constructor(){
this.storageRef = firebase.storage().ref();
}
What you’re referring to getInstance()
is probably Android Studio related.
I’ve created You two little snippets. Hopefully You can adapt them to Your code.
protected getFileUrl(): Promise<any> {
return new Promise((resolve: any, reject: any) => {
this.firebase.storage().ref(`${path}/${to}/${Your}/${file}/`).getDownloadURL().then((downloadUrl: string) => {
console.log('Your download url is: ', downloadUrl);
return resolve(downloadUrl);
}).catch((error: any) => {
console.error('something went wrong while fetching the download url', error);
return reject(error);
});
});
}
protected uploadFile(): Promise<any> {
return new Promise((resolve: any, reject: any) => {
this.firebase.storage().ref(`${path}/${to}/${Your}/${directory}/`).put(this.yourFile).then(() => {
console.log('successfully uploaded Your file');
return resolve();
}).catch((error: any) => {
console.error('something went wrong while uploading file', this.yourFile, error);
return reject(error);
});
});
}
Cheers
Unkn0wn0x
Hi, thanks a lot for the reply. I think what I’m looking for is to connect to a user selected public firebase storage with a storagebucket url, in app. for example:
this.firebase.storage(‘gs://123…appspot.com’).ref(‘inputfolder/test.txt’).put(this.file).then(() => {
this.firebase.storage(‘gs://abc…appspot.com’).ref(‘inputfolder/test.txt’).put(this.file).then(() => {
this.firebase.storage(‘gs://xyz…appspot.com’).ref(‘inputfolder/test.txt’).put(this.file).then(() => {
but the current way with the ‘firebase.storage().ref();’ only connect to a the bucket based on the firebase config file within the app…
do you think this is possible?
or is there a way to do this with thet cloud function?
I think You should have a look at the AngularFire Library.
There You can find a segment related to Ionic. Examples are also provided. Maybe this helps You.
Cheers
Unkn0wn0x