So I'm making an ASP.NET web application where alongside sending some data, the user also has the option to attach files. The plan is that the app will be also used from mobile phone browsers, so I made the file input like this, so clicking it will open the phone camera and allow them to take or attach photos.
<input id="Attachment" runat="server" type="file" accept="image/*" capture="camera" multiple />
And then upon clicking a button to send, the posted files are handled like this.
foreach(string AttachmentName in Request.Files)
{
HttpPostedFile Attachment = Request.Files[AttachmentName];
string FileName = Attachment.FileName;
Stream FileStream = Attachment.InputStream;
BinaryReader br = new BinaryReader(FileStream);
byte[] bytes = br.ReadBytes((Int32)FileStream.Length);
string FileContent = Convert.ToBase64String(bytes);
/* file upload logic here */
}
This seems to work as is. Upon testing, you could take pictures with the phone, they got attached and their data uploaded to my database.
But I am having an issue where sometimes the data uploaded from the attached file - so the value of FileContent - is completely empty. Clearly the file gets posted, as otherwise it wouldn't upload it at all, since the foreach cycle wouldn't run. So it gets half way, yet the file seems to be empty(?).
What could be the cause here? The android device not sending the data properly for some reason? How could I even test or validate the data, when it is simply received from Request?