SAMANTHA MCGUIRE
SAMANTHA MCGUIRE

Reputation: 1

Storing images in an Image column of my table

I'm a student working on some code for a fake company. I need to be able to store photos in a table. I am using the image data type for the column. But everything I've tried so far has not worked.

We have to store pictures for parts customers and the work that is done on a vehicle. I have tried inserting photos through the table data view and I have tried doing it through the data grid view while the program was running.

I am hoping to get an idea of what i could do to be able to allow a user to insert a photo when using this program on their own computer.

Upvotes: 0

Views: 1430

Answers (2)

snitch182
snitch182

Reputation: 723

basicly its not a good idea to store image data in a database because if it the table gets larger its a drain on the database operations.

Rather store it in a file named with the id of the data or a random id you create and save in the database. Like for example 'userpics/user_237862.dat' or jpg depending on the data format for the user with the id 237862.

If you really have to store it in the mysql database use a "blob" format which stores any kind of binary data. Have a look at the size constraints though: https://dev.mysql.com/doc/refman/8.0/en/blob.html

Oh, and better use a table only for pics. Otherwise the table for the users(f.e.) gets very large in size and the search operations will take a very long time if your system gets successful.

best of luck, Karsten

Upvotes: 1

Alagu Veerappan
Alagu Veerappan

Reputation: 68

If you have access to file storage, you could save the file directory path in the database and fetch the image when you need to display it rather than storing it in the database.

Upvotes: 1

Related Questions