I have been looking for this solution for days already, but nothing was satisfactory.
In my database, I have images stored under this command:
UPDATE [dbo].[Jogo]
SET Capa = (SELECT 'metal-gear-solid.jpg' FROM OPENROWSET(BULK
N'G:\Imagens\Desenvolvimento\Locadora\metal-gear-solid.jpg',
SINGLE_BLOB) rs)
WHERE IdJogo = 3
GO
But when I try to retrieve them, all I get is a broken image icon.
When I converted into base 64 I got a result like this:
The view 'data:image/jpeg;base64,UmF0Y2hldF8mX0NsYW5rX0Z1dHVyZS5qcGc=' or its master was not found or no view engine supports the searched locations. The following locations were searched:
Also, when I try to convert it into an image object (Image, Bitmap, WebImage, etc.) I get this:
An image could not be constructed from the content provided.
I believe the images are not properly stored, even though I checked the path and the images are all there. This is as one image is in the database (SQL SERVER, image type): 0x526174636865745F265F436C616E6B5F4675747572652E6A7067
This is my action:
public ActionResult Index()
{
LocadoraEntities context = new LocadoraEntities();
using (context)
{
var listaBytes = context.Jogo.Select(c =>
c.Capa).FirstOrDefault();
byte[] ms = listaBytes.ToArray();
string imagemConvertida = string.Format("data:image/jpeg;base64,
{0}", Convert.ToBase64String(ms));
return View(imagemConvertida);
}
}