最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ASP.NET Request.Files returns file, but with empty content - Stack Overflow

programmeradmin2浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论