I have ImageField in my form. Is there any way to show chosen file before submitting a form? Maybe it is possible in jQuery?
I read that I can somehow access this files with request.FILES, but I think it will be empty before I will submit form.
html. We have two main elements that we will interact with using JavaScript. First, we have a division element that contains the “img” tag. Using Jquery, we will change the “src” attribute of the “img” tag on upload to preview the image.
The HTML Markup consists of an HTML FileUpload control and a DIV which will be used for displaying live preview of multiple images. Note: For the HTML INPUT FileUpload control it is very important to set the HTML5 multiple property to multiple in order to allow multiple file selection.
A thumbnail also means a small and approximate version of a full-size image or brochure layout as a preliminary design step. This is also referred to as a preview image and is a smaller version of the original image.
try this one.
function upload_img(input) {
if (input.files && input.files[0]) {
var src = URL.createObjectURL(input.files[0])
$('#img_id').attr('src', src)
}
}
AND HTML is below.
Thanks.
<form id="form_img">
<input type='file' onchange="upload_img(this);" />
<img id="img_id" src="#" alt="your image" />
</form>
This may helpful to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With