0

In my project I am using this code to insert image to database
  private void pctbPicture_Click(object sender, EventArgs e)
    {
        using (OpenFileDialog openFileDialog1 = new OpenFileDialog())
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
               var filename = openFileDialog1.FileName;
                var file = File.ReadAllBytes(filename);
                // request.Image is byte[]
                request.Image = file;

                Image image = Image.FromFile(filename);
               pctbProizvod.Image = image;

            }
        }
    }

In my database when i try to check value of Image it only says byte array
But when i get data from swagger api i can see huge string of letters and numbers as value of image.
Now i am making dataseding script with test data and i would like to insert data from that string of numbers and letters as byte array in database.
something like this pseudocode
Product pp=new Product(){Image = ConverToByteArray(string that represents byte aray From Swagger) };

any help is appreciated!!
Thanks for trying to help
sasko
  • 207
  • 2
  • 20
  • 1
    See this question https://stackoverflow.com/questions/6733845/c-sharp-convert-a-base64-byte – Jasen Sep 01 '21 at 18:47
  • Could you pls share your final goal or requirement such as how to store image into database and query them to show in the website? I'm sorry for can't understand your issue. – Tiny Wang Sep 02 '21 at 04:50

1 Answers1

1

Solution in my case was

Image=  Convert.FromBase64String("string content");
sasko
  • 207
  • 2
  • 20