0

I have a very interesting question, I have front-end in Angular and backed in Spring Boot, but I do not know how to store the image into SQLite DB. Does anyone have any example or suggestion of where to start?

Si Ci Pin
  • 21
  • 1
  • 5

2 Answers2

0

You basicaly have two options:

  • you can store the path to the image
  • you can store the image itself

In general it's better to store only the path of the image, unless you have a specific reason to start the image itself. If you store the image path, then you can organize the folders as well and you will be able to search for an image by its path.

If you want to store the image itself, then you need to load the image file in memory and store that into a file. But in case you will create backups and have many images, then the storage space used on your server could increase drastically.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
0

I was tempted to flag this as a duplicate of this question, but it seems your question might need more answers than the ones in that question.

The image can either be stored directly in the SQLite DB as a blob or in the filesystem as a file.

Unless you have very hard constraints that force you to store the image in the SQLite DB directly, I would advice that you store just a path to the file in the SQLite DB. Visit this question to read some conversations around these two ways of storing images.

This blog post from grokonez, describes the complete process of how you can store and retrieve images with spring boot and Angular 4. I would advice that you use that as a starting point.

You can also take a look at this simple blog post from dzone to understand a different way of doing this.

Finally, the accepted answer in this question, will help you store your image in the SQLite DB if you choose that route.

draysams
  • 1,199
  • 1
  • 11
  • 18