'Some pdf attachments showed as octet-stream in database
In my ASP.NET MVC web application, I have given the option to users to attached PDF files or JPEG files in the view.
So once the user uploads the file I'm saving those files by considering file type.
The issue is I got complaints that some attachments can't view the other user. So I checked the database and the PDFfiles attached by some users not passed to the database but the file type it shows as octet-stream
This is how it stored in the database
This is how my code in the controller
foreach(PurchasingItems item in appRequest.PurchasingItemsList)
{
HttpPostedFileBase file = Request.Files["ImageData" + item.TempID];
item.Attachment = ConvertToBytes(file);
item.FileType = Path.GetFileName(file.ContentType);
}
public byte[] ConvertToBytes(HttpPostedFileBase image) {
byte[] imageBytes = null;
using(BinaryReader br = new BinaryReader(image.InputStream)) {
imageBytes = br.ReadBytes(image.ContentLength);
}
return imageBytes;
}
Since the system is almost live I need to overcome with a solution to resolve this as soon as possible. So anyone knows what is the issue here and how to solve it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

