保存值时输入不是有效的base-64字符串错误

时间:2019-03-02 09:44:26

标签: arrays asp.net-mvc entity-framework asp.net-mvc-4 base64

我尝试保存带图片和不带图片的数据,但我不知道输入错误是不是有效的base-64字符串错误,这是这样的:

enter image description here

这是控制器的代码

 public ActionResult Scan()
        {
            string ScanData;
            // blob(image) coming in
            using (Stream receiveStream = Request.InputStream)
            {
                using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
                {
                    // Reading blob(image)
                    ScanData = readStream.ReadToEnd();
                }
            }
            // Removing extras from blob(image)
            byte[] Data = Convert.FromBase64String(ScanData.Replace("data:;base64,", string.Empty).Replace("data:application/octet-stream;base64,", string.Empty));
            //blob(image) Temporary held until the rest of data comes in to "Create" method.
            TempData["ScannedImage"] = Data;
            //System.IO.File.WriteAllBytes("FileName.png", Data); // save scanned images to files.
            return null; // return nothing, the rest of the data will be processed in the "Create" method.
        }

这是一个创建操作

public async Task<ActionResult> Create(Inbox model/*,IEnumerable<HttpPostedFileBase>File*/)
{
    var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
    if (ModelState.IsValid)
    {
        model.User = currentUser;  
        var max = new Inbox();
        max.File = TempData["ScannedImage"] as byte[];//from "Scan" method, converted back to byte[]
        max.NameWared = model.NameWared;
        db.Inboxs.Add(model);
        db.SaveChanges();
        string url = Url.Action("List");
        return Json(new { success = true, url = url });
    }
    return View(model);
}

这是我的模型

    {
    public class Inbox
    {
        [Key]
        public int InboxId { get; set; }

        public string WaridNO { get; set; }

        public string NameWared { get; set; }
          public byte[] File { get; set; }


        [NotMapped] // Won't be mapped to db, only used to show images on page.
        public string image { get; set; }
   }
}

当我单击以保存值时,我正在尝试上传值,该消息告诉我我需要一些帮助人员

0 个答案:

没有答案