0

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?
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193

2 Answers2

1

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

Bharat Vishe
  • 153
  • 1
  • 2
  • 12
1

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.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • hello, thank you for the help, i tried to look into the cloud storage for firebase, i saved my svg there but couldn't find any way to turn it into an ImageView in android, any Idea how to do that? – Yakin Wissem Sep 07 '21 at 15:44
  • "couldn't find any way to turn it into an ImageView in android" doesn't provide enough information to help. But in short, once you have uploaded the image to Firebase Storage you can get the [download URL](https://stackoverflow.com/questions/53299915/how-to-get-offline-uploaded-file-download-url-in-firebase/53300660#53300660). Using this URL you can set an image to your ImageView using [Glide](https://github.com/bumptech/glide), for example. – Alex Mamo Sep 08 '21 at 05:03
  • hi, I tried glide and many other ways to implement this idea, there seems to be no way to do it, the problem is in android and not in firebase, android has no way to turn an SVG to an ImageView at runtime by code, tried many methods but they simply didn't work because its not supported, feels bad, now I have to find some other way to solve the problem. thank you for the help – Yakin Wissem Sep 10 '21 at 12:29
  • If you have a hard time converting it, please show us what you have tried by posting a new question, here on StackOverflow, using its own [MCVE](https://stackoverflow.com/help/mcve), so I and other Firebase developers can help you. – Alex Mamo Sep 11 '21 at 07:38