将二进制数据保存到表中时,我得到了NULL

时间:2019-01-04 10:58:23

标签: c# asp.net-web-api

在这里,我试图将文件上传到数据库中,但是我在数据库中得到NULL
请给我任何提示。

var httpRequest = HttpContext.Current.Request;
var httpPostedFile = HttpContext.Current.Request.Files["file"];

foreach(string file in httpRequest.Files) 
{
    var postedfile = httpRequest.Files[file];
    var FileName = httpPostedFile.FileName;
    int fileSize = httpPostedFile.ContentLength;
    byte[] fileByteArray = new byte[fileSize];
    httpPostedFile.InputStream.Read(fileByteArray, 0, fileSize);
    HttpPostedFile postedFile = HttpContext.Current.Request.Files[file];
    byte[] bytes;

    using(BinaryReader br = new BinaryReader(postedFile.InputStream)) 
    {
        bytes = br.ReadBytes(postedFile.ContentLength);
    }
    Temp_Table = new Temp_Table {
        Profiledata = bytes
    };
    db.Table.Add(_temp);
    db.SaveChanges();

0 个答案:

没有答案