Trying to download Image which is stored sql server in the form of bytes and was able to download the image, but i'm getting the corrupted image and was not able to open the downloaded image
Here is my code
data.imageData is the Byte[] data of image which is retrieved from SQl server
data.imageName is the Name of file
public class Attachmets
{
public byte[] Imagedata {get;set;}
public string ImageName {get;set;}
}
public static HttpResponseMessage DownloadImage(Attachments data, bool isInline)
{
isInline = false;
var response = new HttpResponseMessage();
var memoryStream = new MemoryStream(data.ImageData);
response.Content = new StreamContent(memoryStream);
var headers = response.Content.Headers;
headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
headers.ContentDisposition =
new ContentDispositionHeaderValue(isInline ? DispositionTypeNames.Inline : DispositionTypeNames.Attachment)
{
FileName = Path.GetFileName(data.ImageName)
};
return response;
}