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

139
Views
How to set image to input file field

I have the following input:

  <input type="file" asp-for="ScreenShotImage" id="offer-client-image"/>   

The application is making screenshot-image from the div calculator, and I want to set that image to id="offer-client-image" input. When the user submit the form, the image will be uploaded as well.

I tried like this, but it doesn't work:

 document.getElementById("offer-client-image").file = document.getElementById('canvas').toDataURL()

Any help is appreciated!

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

0

I don't think using an actual file input is relevant because the user doesn't have to choose anything.

Maybe you could handle this like this:

const form = document.getElementById("the_form")
const cvs = document.getElementById("the_canvas")

form.onsubmit = function(e) {
  e.preventDefault()
  const data = new FormData(form)
  cvs.toBlob(img_blob => {
    data.append("img_file", img_blob)
    // send your form
    fetch("https://example.com/post_url", {
      method: "POST",
      body: data
    });
  })
}
<form id="the_form">
  <input type="submit" />
</form>
<canvas id="the_canvas"></canvas>

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!