Я сохраняю файл в базу данных MySQL как blob.Не могли бы вы помочь мне, как я могу скачать этот BLOB-файл в виде файла?У меня есть данные BLOB и ContentType
в базе данных.Вы можете увидеть мой метод для загрузки ниже.Я искал более недели, но я не мог сделать это.Я также не знаю, что я могу скачать напрямую через метод или мне нужно написать ajax.Я высоко ценю вашу помощь и содействие.Большое спасибо!
Метод:
public HttpPostedFileBase Indir()
{
using (ISession session=FluentNHibernateHelper.OpenSession())
{
var doc = new Document();
var docDet = new DocumentDetail();
doc = session.Query<Document>().FirstOrDefault(x => x.Id == 5);
docDet = session.Query<DocumentDetail>().FirstOrDefault(x => x.DocumentId == doc.Id);
var test = new MemoryPostedFile(docDet.File, doc.DocumentName, doc.DocumentExtention);
return test;
}
}
Класс:
public class MemoryPostedFile:HttpPostedFileBase
{
private readonly byte[] fileBytes;
public MemoryPostedFile(byte[] fileBytes, string fileName = null, string ContentType = null)
{
this.fileBytes = fileBytes;
this.FileName = fileName;
this.ContentType = ContentType;
this.InputStream = new MemoryStream(fileBytes);
}
public override int ContentLength => fileBytes.Length;
public override string FileName { get; }
public override string ContentType { get; }
public override Stream InputStream { get; }
}