Yakin Wissem
Yakin Wissem

Reputation: 57

what is the best way to save an svg in firebase?

I have an Android app where I want to implement a feature where the users can upload SVGs, the SVG would then be saved in a firebase Realtime database, then other users can see it and interact with it, the reason why I chose SVGs over regular photos or PNGs is because it's very small and don't consume storage or data to load, plus they are better with multiple display densities and different screen ratios, the problem is that I don't know if that is doable if it is I don't know what is the format its gonna be saved as, because I had an idea of saving the SVG path but didn't find a way to convert it into a drawable/vector, or even how to get the path from an SVG, hopefully, I described my problem/question clearly(sorry my eng is bad)

  1. How to save SVG/vector in Firebase Realtime Database?
  2. How to turn it back to a drawable/ImageView/vector...anything that's displayable?
  3. Is there a better approach to this idea/problem?

Upvotes: 0

Views: 1808

Answers (2)

Alex Mamo
Alex Mamo

Reputation: 138844

How to save svg/vector in Firebase Realtime Database?

As Bharat Vishe mentioned in his answer, you can convert your files to base64 and store them in the Realtime Database. You can simply do that using the answer from the following post:

How to turn it back to a drawable/ImageView/vector...anything that's displayable?

To be able to display the image that comes from the Realtime Database, you need to decode the base64 String back to an image using the answer from the following post:

Is there a better approach to this idea/problem?

Yes, you should consider hosting those SVG files into Cloud Storage for Firebase:

Cloud Storage for Firebase is built for app developers who need to store and serve user-generated content, such as photos or videos.

Upvotes: 1

Bharat Vishe
Bharat Vishe

Reputation: 303

You can convert .svg file to base64 and store it as plain text in firebase.

Upvotes: 1

Related Questions