Save an image to a mysql
cmd = new MySqlCommand(query, con);
cmd.Parameters.AddWithValue("@image", client.Image);
I tried this method, but saved "System.Image.bitmap" on the database
How can I save the image to the mysql database?
25 Replies
btw
my client.image variable is this:
public Image? Image { get; set; } = image;
You'll want to store images with a service that's built for storing large amounts of binary data, not in your SQL database.
can base64 encode it if all else fails
But what's happening is happening because
ToString()
is implicitly being called on client.Image
, which returns the type name by defaulti'll try
You should be using whatever MySQL's type for binary data is
yup
i said if all else fails
store as bytes or blob, etc
yes, i'm using a binary type
And for smaller images it can be ok to store them in the database
i can't, unfortunately
also true
The scope of this project, is for a local store
then why not just move the images to a specific location and just store the path to it?
is that not allowed?
The problem is, if the computer breaks, the images gets lost forever
That's always going to be true
isnt that the same if the db is hosted on the same computer?
What does storing them in a database solve
and it was promissed to the client that everything will be have backup
so the db is online
gotcha
not in this case, the db is online
I didn't say store them on the client's filesystem, I said store them somewhere that's designed for storing files
i know, but i can't do this
i'll try to convice my boss to buy AWS for images
anyways, thanks
Fair enough, again if the images are small there's probably not a huge problem with storing them in the database
Just make sure you're storing them in their own table
worked converting to base64
lol
Just saying, but storing files in the database will be slow as shit
Not only will it slow down your queries and bloat the db
You'll be unable to use compression and caching
agree