EDIT:
Here's a create script for the table minus the constraints on the keys for brevity.
CREATE TABLE [dbo].[ProfileFile](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ProfileID] [int] NOT NULL,
[FileTypeId] [int] NOT NULL,
[Data] [image] NOT NULL
EDIT:
Attempt to bypass NHibernate to access data in service layer
byte[] temp = (byte[])this._baseModelRepository.CurrentSession.CreateSQLQuery("SELECT Data FROM ProfileFile WHERE ProfileID = :ID").SetParameter("ID", id).UniqueResult();
EDIT: After checking binary data saved in db, it seems that the entire file is uploaded and that my issue is actually on the side of displaying the image.
The image is not rendered but I can follow the action link to download the file but it is cut off at 8KB.
ProfileFile Model class Data field as generated by NHibernate
public virtual System.Byte[] Data { get; set; }
I hard coded the MIME type and file name for now while getting this set up.
public ActionResult GetProfilePhotoByID(int profileID)
{
var profileFile= //Load file object from DB by profileID
byte[] byteArray = profileFile.Data;
string mimeType = "image/jpg";
string fileName = "ProfilePhoto.JPG";
return File(byteArray, mimeType, fileName);
}
Using debugger I found that the size of profileFile.Data is 8000. Maybe this is a NHibernate restriction?
Also, this is running with IIS and I am getting the same effect in Chrome, Firefox, and IE but am mainly testing in Chrome.
Original question: I am trying to allow the user to upload a profile photo which I will then later serve up on their profile page. Unfortunately, the image file is not completely uploaded and is cut off at 8 KB. Below are simplified versions of some of the more important code segments.
Index View snippets
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "profileform", enctype = "multipart/form-data" }))
<input type="file" id="photo" name="photo" />
Controller post action has HttpPostedFileBase photo
parameter
byte[] input;
if (photo != null && photo.ContentLength > 0)
{
input = new byte[photo.ContentLength];
photo.InputStream.Read(input, 0, photo.ContentLength);
if (model.ProfileFiles == null)
{
model.ProfileFiles = new List<Core.Model.ProfileFiles>();
}
model.ProfileFiles.Add(new Core.Model.ProfileFiles()
{
ProfileID = model.ID,
Profile = model,
Data = input
});
}
Model class is generated with NHibernate. The relevant field is
// One To Many:
public virtual IList<ProfileFile> ProfileFiles { get; set; }
Just comment if more information is needed.