my requirement is i have to update images in both database and application using
fileuploaderjs file. but i am to upload either in application or database. below is
my code ,please help me.and my database with name Images have two columns namely
imagename,image
**.cshtml**
$(document).ready(function () {
alert('in');
var uploader = new qq.FileUploader({
// pass the dom node (ex. $(selector)[0] for jQuery users)
element: document.getElementById('file-uploader-demo1'),
action: '/Home/DigitalAssetsFileUpload?fileType=image',
multiple: false,
allowedExtensions: ['jpg', 'png', 'gif'],
debug: true,
onComplete: function (id, fileName, responseJSON) {
alert('inserted');
}
});
});
157px;">
**controller class**
this is controller which i have .
public void DigitalAssetsFileUpload(string recFileType = "image")
{
long fileSizeInBytes = 0;
string fileType = HttpContext.Request.QueryString["fileType"];
string phyicalFilePath = Server.MapPath("~/Images");
string uploadedFileName = HttpContext.Request.Headers["X-File-Name"];
uploadedFileName = HttpUtility.UrlDecode(uploadedFileName);
string fileExt = Path.GetExtension(uploadedFileName);
Stream inputstream = null;
inputstream = HttpContext.Request.InputStream;
string storagePath = phyicalFilePath;
if (!Directory.Exists(storagePath))
{
System.IO.Directory.CreateDirectory(storagePath);
}
string pFilePath = storagePath + "\\" +uploadedFileName;
FileStream fileStream = new FileStream(pFilePath, FileMode.OpenOrCreate);
if (inputstream == null)
{
System.Diagnostics.Debug.WriteLine("Application", "stream is null");
throw new NullReferenceException("stream is null");
}
fileSizeInBytes = inputstream.Length;
using (fileStream)
{
using (inputstream)
{
byte[] buffer = new byte[16 * 1024];
int bytesRead;
while ((bytesRead = inputstream.Read(buffer, 0, buffer.Length)) > 0)
{
fileStream.Write(buffer, 0, bytesRead);
}
}
}
BinaryReader br = new BinaryReader(inputstream);
byte[] data = br.ReadBytes((Int32)inputstream.Length);
string constr = "data source=localhost; initial catalog=sample; persist security
info=True; Integrated Security=SSPI";
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand("Insert_Images", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@Image", SqlDbType.VarBinary).Value = data;
com.Parameters.Add("@imagename", SqlDbType.VarChar).Value = uploadedFileName;
con.Open();
int result = com.ExecuteNonQuery();
con.Close();
}
plz suggest any answer to me....................................................
RAGHUNATHPosted Feb 27, 2014, 1:20 AM
actually once we read stream data the content present in that becoming null.
so i cannot able to use further that stream.. that's why i am not able to upload both in database and application folder..
i am able to upload either in database or application folder.
RAGHUNATHPosted Feb 27, 2014, 1:17 AM
but i need to upload files through client side using uploader.js file. and i need to upload both in database and application folder..
Vithal WadjePosted Feb 26, 2014, 12:43 PM
Lakshmanan Sethu SankaranarayanPosted Feb 26, 2014, 12:07 PM