TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
RAGHUNATH
1.7k
63
49.6k
cannot upload images into database and application(fileuploa
Feb 26 2014 6:28 AM
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**
<link href="../../Content/fileuploader.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/fileuploader.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(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',
template: '<div class="qq-uploader">' +
'<ul class="qq-upload-list"></ul>' +
'<a class="qq-upload-button" >Upload a file</a>' +
'</div>',
multiple: false,
allowedExtensions: ['jpg', 'png', 'gif'],
debug: true,
onComplete: function (id, fileName, responseJSON) {
alert('inserted');
}
});
});
</script>
<div style="margin: -5px 0pt 4px 54px; position: relative; position: relative;">
<div id="file-uploader-demo1" style="text-align: right; width: 0px; padding-left:
157px;">
</div>
</div>
**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....................................................
Reply
Answers (
4
)
cookie value
how to use Line Chart in rdlc reports using MVC4, ASP.Net