Привет, ребята. Я пытаюсь отобразить изображения из базы данных. Я сохраняю изображения в базе данных, но ничего не отображается. Как это можно исправить здесь, в моем коде
* 1005?* это мой вид модели
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Archive.Models
{
public class Inbox
{
[Key]
public int Id { get; set; }
public IEnumerable<HttpPostedFileBase> Files { get; set; }
public ApplicationUser User { get; set; }
public object UserId { get; internal set; }
}
}
и здесь детали
namespace Archive.Models
{
public class AllFiles
{
public int Id { get; set; }
public string ContentType{ get; set; }
public byte[] Imagebytes { get; set; }
}
}
здесь я конвертировать
using System.Web;
using System.IO;
namespace FileUpload.Service
{
public class FileUploadService
{
// GET: AllFiles
public void saveFileDetails(HttpPostedFileBase file)
{
AllFiles newfile = new AllFiles();
newfile.ContentType = file.ContentType;
newfile.Imagebytes = ConvertToBytes(file);
ApplicationDbContext db = new ApplicationDbContext();
{
db.AllFiless.Add(newfile);
db.SaveChanges();
}
}
public byte[] ConvertToBytes(HttpPostedFileBase file)
{
byte[] imagebytes = null;
BinaryReader reader = new BinaryReader(file.InputStream);
imagebytes = reader.ReadBytes((int)file.ContentLength);
return imagebytes;
}
}
}
и вот мой контроллер
public async Task<ActionResult> Create(Inbox model)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
FileUploadService service = new FileUploadService();
foreach (var item in model.Files)
{
service.saveFileDetails(item);
}
var max = new Inbox();
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
и это мои детали просмотра
@foreach(var image in Model)
{
var base64 = Convert.ToBase64String(image.Files);
var imgSrc = String.Format("data:{0};base64,{1}",image.ContentType ,base64);
<img src="@imgSrc"/>
}
я пытаюсь отобразитьизображения здесь, но это не показывает, в чем проблема, ребята, пожалуйста, ребята, я так стараюсь, я спрашивал здесь, но я не получил images
изображение в базе данных этосохранено вот так здесь