My webapp needs to include the feature to save SVG files to the database so that they can be fetched and rendered in the browser with the ability to make use of CSS to style parts of the image based on parsing the XML. Storing as base64 does not do the job, because then it is rendered to the DOM without making the XML available for parsing and manipulation.
The docs on working with binary files in orientjs are extremely thin, and I cannot find any suitable examples out there, so I'm pretty much stuck.
Any help would be appreciated.
An
svgis nothing else but a string of XML syntax.E.g. consider the following svg:
You pretty much have two options:
svgas a simpleStringsvgas abase64encodedStringIf your
svgonly contains ASCII characters, method 1 should be fine. Otherwise you need to use method 2. Note: method 2 can be used to store any type of file!!!An example of both methods in
OrientJS:Then create a file
app.jsand run it:This code will create a class
Examplethat has propertiesimageandtypeand will then create two vertices: one where thesvgis saved as a string and one where thesvgis saved as abase64encoded string. It also shows how to retrieve both images again into javascript.After you've retrieved the files, you can then pass them to your front-end and render them on the DOM, at which point any CSS styles that are defined on the DOM will also be applied.
I hope that answers your question.