Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
display uploaded image in edit form

I have a edit form where I have to display the previously uploaded image by the user. I searched on internet and tried with the solutions but it is not working. How can I show the uploaded image and it's name?

<div class="col-md-4">
    <div class="form-group ">
        <label class="required title_header">Image</label>
        <input type="file" class="form-control" id="ImageFile" required name="ImageFile" accept="image/*">
    </div>
</div>
<div class="row">
    <div class="col-md-4">
        <div id="i_imagePrvw" class="thumbnail" style="display:none">
            <img class="img-responsive" id="i_targetImg" style="display:block; object-fit:fill;height:140px;width:120px;" />
            <div class="caption">
                <a href="#" onclick="clearPreview()"><i class="glyphicon glyphicon-trash"></i></a>
                <p id="description"></p>
            </div>
        </div>
    </div>
</div>

I am retrieving the data in json format. In console log I am getting the values as::

"ImageTitle":"98570125698.jpg",
"ImagePath":"E:\\projects\\fis\\UI\\Files\\98570125698.jpg"

I am trying to set the image name and file via this code, but it is not working.

var image_ = data.firm_model[0].ImagePath;
$('#i_targetImg').html('<img src="' + image_ + '"/>');
$('#ImageFile').val(data.firm_model[0].ImageTitle);

Showing errors as

Not allowed to load local resource: file:///E:/projects/fis/UI/Files/98570125698.jpg
Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.

Please do not mark as possible duplicate, first read the whole problem. I am trying to set the image and image name but I do not know, how to do. If you have the solution, please do a reply. Thank You!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It is very simple. Assuming that you are keeping your image (jpg) files in the folder Files inside your project. Then you can preview the uploaded image via using this code,

var image_ = "/Files/"+ data.firm_model[0].ImageTitle;
$('#i_targetImg').attr('src', image_);

You should be careful that the Files folder should be inside your root project directory. And regarding setting the name of the uploaded file in input attribute, please go through this link, How to set a value to a file input in HTML?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!