0
例外是當我試圖轉換後的圖片保存爲Base64格式:驗證在ASP.NET的失敗一個或多個實體的實體框架
public async Task<HttpResponseMessage> Upload()
{
if (!Request.Content.IsMimeMultipartContent())
{
Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
var provider = GetMultipartProvider();
var result = await Request.Content.ReadAsMultipartAsync(provider);
//Get Album name from Form
var titleOfAlbum = GetTitleOfAlbum(provider);
//get path to file
var pathToCoverDecoded = result.FileData.First().LocalFileName;
//ENCODE IMAGE TO BASE64
var bMap = new Bitmap(pathToCoverDecoded);
byte[] imageBtes;
string base64;
using (MemoryStream ms = new MemoryStream())
{
bMap.Save(ms, bMap.RawFormat);
imageBtes = ms.ToArray();
base64 = Convert.ToBase64String(imageBtes);
}
Album al = new Album();
al.Title = titleOfAlbum;
al.PathToCover = base64;
db.Albums.Add(al);
db.SaveChanges();
return new HttpResponseMessage(HttpStatusCode.OK);
}
異常信息的截圖
告訴我請爲什麼我得到這個例外,我如何解決它?
您可以閱讀驗證消息。請提供 –
如上所述「請參閱EntityValidationErrors」proeprty。它是消息:)上面的第四個屬性: –
試圖找出哪個字段,驗證失敗。這個錯誤與代碼無關。 –