For what it's worth, I also ran into the same problem listed here. For me the issue was actually with the upload code not the download code:
Public Sub ImportStream(FileStream As Stream)
'Use this method with FileUpload.PostedFile.InputStream as a parameter, for example.
Dim arrBuffer(FileStream.Length) As Byte
FileStream.Read(arrBuffer, 0, FileStream.Length)
Me.FileImage = arrBuffer
In this example the problem is I declare the Byte array
arrBuffer with a size one byte too large. This null byte is then saved with the file image to the DB and reproduced on download. The corrected code would be:
Dim arrBuffer(FileStream.Length - 1) As Byte
Also for reference my
HttpResponse code is as follows:
'SetContentType() is a function which looks up the correct mime type
'and also adds and informational header about the lookup process...
context.Response.ContentType = SetContentType(objPostedFile.FileName, context.Response)
context.Response.AddHeader("content-disposition", "attachment;filename=" & HttpUtility.UrlPathEncode(objPostedFile.FileName))
'For reference: Public Property FileImage As Byte()