I need to preview the image before upload.I was able to pass the file path from view to controller,in the controller using memory stream class i am trying to preview the image before saving it to database.Could any one provide me any sample or example for this
Thanks!
I need to preview the image before upload.I was able to pass the file path from view to controller,in the controller using memory stream class i am trying to preview the image before saving it to database.Could any one provide me any sample or example for this
Thanks!
1Please improve your question so it is possible to answer: tag with language you are using, clarify where "file path" is pointing to (local user machine file path, server side path to existing file, server side path to temporary file, some other path?).
– Alexei Levenkov
CommentedJul 3, 2012 at 4:21
i am using asp mvc3.The path is local user machine file path which is "C:/foldername/imagename.jpg".I need to preview image before upload using server side scripting.@Alexeli Levenkov
– SahithiPinisetty
CommentedJul 3, 2012 at 4:26
1Please edit your question with above information, and specify language (VB.Net, IronPython...). Note: local file path is not exactly useful for server side script as server obviously can't access file on user's machine. How/why you are getting this path to server?
– Alexei Levenkov
CommentedJul 3, 2012 at 4:34
Add a ment
|
2 Answers
2
Reset to default
5
<script type="text/javascript">
function readfile(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#image_preview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
<form id="form1">
<input type='file' onchange="readfile(this);" />
<img id="image_preview" src="#" alt="your image" width="200" height="200"/>
</form>
I have created bin also, try using this link http://codebins./codes/home/4ldqpc4