public JsonResult gallaryAudioAdd(Gallery_tbl imageGalleryParam,ImageBal imageParam)
{
try
{
var Audio_folder_path = Server.MapPath("~/audioClip/");
TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTime indianTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);
var max_id = dc.Gallery_tbls.Count() == 0 ? 0 : dc.Gallery_tbls.Max(x => x.auto_id);
Gallery_tbl imageGallery_list = new Gallery_tbl();
imageGallery_list.name = imageGalleryParam.name;
imageGallery_list.remark = imageGalleryParam.remark;
imageGallery_list.upload_date = indianTime;
imageGallery_list.auto_id = int.Parse(max_id.ToString()) +
if (imageGalleryParam.gallery_type == "audio")
{
string audioClip_name = byteArrayToImage(imageParam.imageData.Split(',')[1], Audio_folder_path, (int.Parse(max_id.ToString()) + 1).ToString() + ".mp3");
imageGallery_list.gallery_url = "/audioClip/" + audioClip_name;
}
imageGallery_list.status = 1;
imageGallery_list.description = imageGalleryParam.description;
imageGallery_list.gallery_type = imageGalleryParam.gallery_type;
dc.Gallery_tbls.InsertOnSubmit(imageGallery_list);
dc.SubmitChanges();
return Json(new
{
flag = true,
message = "Insert Successfully",
data = imageGallery_list
});
}
catch (Exception ex)
{
return Json(new
{
flag = true,
message = ex.Message.ToString()
});
}
}
public static string byteArrayToImage(string Content, string filePath, string filaName)
{
var bytes = Convert.FromBase64String(Content);
using (var imageFile = new FileStream(filePath + filaName, FileMode.Create))
{
imageFile.Write(bytes, 0, bytes.Length);
imageFile.Flush();
}
return filaName;
}
Catching “Maximum request length exceeded”
The problem is that the exception is thrown before the upload button's click-event, and the exception happens before my code is run. So how do I catch and handle the exception?