I need to save a jpg image to database
in the database type of this property is nvarchar(max)
so i need to serialize and deserialize this property like this:
private byte[] HexStringToObject(string value)
{
SoapHexBinary shb = SoapHexBinary.Parse(value);
return shb.Value;
}
private string ObjectToHexString(object value)
{
if (value == null)
return "";
SoapHexBinary shb = new SoapHexBinary((byte[])value);
return shb.ToString();
}
but there is a problem,, I dont know the problem is related to serialize or deserialize method
just when I want to see this image via:
public FileResult Initialpicture(int? propertyId)
{
if (propertyId == null)
return null;
IProperty image = Repository<IProperty>.Get(propertyId);
if (image.Value == null)
return null;
return File((byte[])image.Value, "image/jpg");//Get of Value use deserialize method to get byte[]
and in the browser i just can see small part of image,and the error ” Image corrupt or truncated:”
}
what is the problem?
Probably your database or your ORM if you have any, will truncate the byte array for example to 12000 bytes.