title: Download Blob as a file in ASP.NET MVC
body: <p>I am saving a file to MySQL database as blob. Could you please help me, how can I download this blob as a file? I have blob data and <code>ContentType</code> in the database. You can see my method for downloading below. I have been searching for over a week, but I couldn't make it. I also don't know that I can download directly over method or I need to write ajax. I highly appreciate your help and assistance. Thanks a lot!</p>
  
  <p><strong>Method:</strong></p>
  
  <pre><code>public HttpPostedFileBase Indir()
  {
      using (ISession session=FluentNHibernateHelper.OpenSession())
      {
          var doc = new Document();
          var docDet = new DocumentDetail();
  
          doc = session.Query&lt;Document&gt;().FirstOrDefault(x =&gt; x.Id == 5);
          docDet = session.Query&lt;DocumentDetail&gt;().FirstOrDefault(x =&gt; x.DocumentId == doc.Id);
  
          var test = new MemoryPostedFile(docDet.File, doc.DocumentName, doc.DocumentExtention);
          return test;
      }
  }
  </code></pre>
  
  <p><strong>Class:</strong></p>
  
  <pre><code>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 =&gt; fileBytes.Length;
  
      public override string FileName { get; }
      public override string ContentType { get; }
      public override Stream InputStream { get; }
  }
  </code></pre>