C
C
CJDmitry2018-03-27 14:33:44
ASP.NET
CJDmitry, 2018-03-27 14:33:44

Switching from ASP Net to ASP Net Core?

Good day!
Need help in resolving the issue. There was a Net Framework 4.6 project in which the image was converted to an array of bytes and placed in the database. Conversion code:

public static byte[] imageToByteArray(string imagePath)
        {
            MemoryStream ms = new MemoryStream();
            System.Drawing.Image.FromFile(imagePath).Save(ms, ImageFormat.Jpeg);
            return ms.ToArray();
        }

Next, I make a project on ASP NET Core MVC. I tried various ways to pull out the image, but none of them help!
Tried like this, directly in the model:
<img class="" src="data:image/jpeg;base64,@(Convert.ToBase64String(ps.GetImage(p.Id)))" alt="@p.Name">

Tried saving to file. The file is saved, but the image does not open:
Byte[] img = await Prods.GetImage(p.Id); //Функция получает массив байт и БД
string path = Path.Combine(uploads, p.Id.ToString() + ".jpg");
await System.IO.File.WriteAllBytesAsync(path, img.ToArray())

What could be the problem, I can not understand. I fight already the second day. Tell!
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-03-27
@cjdmitri

what do you need in the end?
e.g.
Display Image From Byte Array In ASP.NET MVC
www.binaryintellect.net/articles/e6d71127-1f12-455...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question