hi i want to attach multiple file using jquery ajax and save it in a column of table whose datatype is blob.i have no idea what different property need to be taken in model class i have taken a single variable Attach of HttpPostedFileBase type model class
public class Ipcell
{
public string CaseId { get; set; }
public HttpPostedFileBase Attach { get; set; }
}
view is a partial view where file upload button is available apart from other value and submit button is given at bottom.after attaching multiple file then click on submit button all values in that partial view along with different attachment should be saved in database,i.e attachments in a blob type column of table.
@model Smart.Models.Ipcell
<div>
<div> caseid<input id="Rcid" type="text" value="@Model.CaseId" /></div><br />
<div>attachment<input id="Rattc" type="file" style="margin-left:7%;padding-left:30%;"/></div><br />
<input id="Rsub" type="submit" />
</div>
on clicking 'RSub' data should be save to data base through controller using jquery ajax. jquery side
$(document).on("click", '#Rsub1', function (e) {
var casedetail42={};
var casedetail42s=[];
casedetail42["CaseId"] = $('#Rcid').val();
casedetail42["Attach1"] =$('#Rattc').prop('files')[0];
casedetail42s.push(casedetail42);
$.ajax({
type:"POST",
url:"/Home/RaisePReq",
data:JSON.stringify(casedetail42s),
contentType:"application/json; charset=utf-8",
datatype:"json",
success:function(r){
alert(r);
},
});
});
Controller side, in controller side i am not getting any value in stream fs
[HttpPost]
public JsonResult RaisePReq(List<Pcell> casedetail42)
{
Byte[] bytes = null;
Stream fs = casedetail42[0].Attach1.InputStream;
BinaryReader br = new BinaryReader(fs);
bytes = br.ReadBytes((Int32)fs.Length);
try
{
conn.Open();
string qry1_1 = "query for insert file upload value in a column with blob format"
OracleCommand command = new OracleCommand(qry1_1, conn);
command.Parameters.Add(":IBD_ATTACHMENTS", bytes);
int insertedRecords = command.ExecuteNonQuery();
return Json(insertedRecords);
}
}
how to achieve it any idea would be appreciated.