I want to open a file (it may be any type of file like .txt
, .doc
, .pdf
or an image..) that is stored to the database in blob
format.
I execute an ajax call to get the blob response:
jQuery
$.get("ajax.aspx?t=getExpAttachedFile&expFileId=" + id, function (data) {
console.log(data);
if (data) {
var arr = [];
arr.push(data);
//Not able to get the file type here..
var oMyBlob = new Blob(arr, { type: '...' });
var url = URL.createObjectURL(oMyBlob);
window.open(oMyBlob);
} else {
// no data
}
});
C# (getting the stored blob file from db)
private void getExpAttachedFile() {
SessionProvider sp = (SessionProvider)Session[Session.SessionID];
eDbs.DbeStudio dc = new DbeStudio( sp.ConnString );
var data = Request["expFileId"];
try {
var fileBlob = dc.SS_Aplication_FileBlobs.FirstOrDefault ( p=>p.ID == Convert.ToInt32(data));
if (fileBlob != null) {
Response.Write( fileBlob.Blob );
}
}
catch {
Response.Write( "0" );
}
}
The data contain the blob string, but I am unable to transform in to the initial file.