(RESOLVED) What's better format to save image in Firestore?

This is my working code

	uploadBase64(folder: string, name: string, base64: string) {
		const path = `${folder}/${Date.now()}_${name}`; // full path file
		const ref = this.storage.ref(path);

		const task = ref.putString(base64, 'data_url'); // upload task
		return this.getDownloadUrl(task, ref);
	}

	private getDownloadUrl(uploadTask: AngularFireUploadTask, ref: AngularFireStorageReference): Observable<string> {
		return from(uploadTask).pipe(switchMap(() => ref.getDownloadURL()));
	}

So you can call this function to other function

	async upload() {
		const url = await this.uploadBase64('thumb', 'image.jpg', 'data:image/jpeg;base64,...').toPromise();
		console.log(url);
	}

And of course you can access with normal observable

	upload() {
		this.uploadBase64('thumb', 'image.jpg', 'data:image/jpeg;base64,...').subscribe(url => {
			console.log(url);
		});
	}
1 Like