Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
HTML getting an image from a file upload

I am working through an old project and trying to fix a few bugs.

I have a file upload in HTML

function updateImage() {
  circleArray = [];
  newPic = `id="taco" width="300" height="300"  src="${$(
    "#myFile"
  ).val()}" alt="prime.png"`;
  $("#hide").empty();
  $("#hide").append(`<img ${newPic}>`);
  makeCanvas();
}
<form>
  <input type="file" id="myFile" name="filename">
  <button id='submit'>Submit</button>
</form>

When I click the submit button I have a function that should update the image displayed with the newly uploaded image.

It seems like the file is uploaded but I am accessing it incorrectly.

I see the following error

GET c:\fakepath\IMG_0544.jpg net::ERR_UNKNOWN_URL_SCHEME

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

  1. I'm unable to reproduce the problem in your dynamic "code snippet", but it's pretty clear what's happening.

  2. The error GET c:\fakepath\IMG_0544.jpg net::ERR_UNKNOWN_URL_SCHEME means that your browser was trying to access a file on your C:\ drive as though it were a remote URL. You can't do that :)

  3. ONE POSSIBLE SOLUTION: try uploading the image and rendering it as an "embeddd image", per this article:

    https://www.thesitewizard.com/html-tutorial/embed-images-with-data-urls.shtml

  4. ANOTHER POSSIBLE SOLUTION: Use FileReader.readAsDataURL():

    https://www.tutorialrepublic.com/faq/how-to-preview-an-image-before-it-is-uploaded-using-jquery.php

about 4 years ago · Juan Pablo Isaza Denunciar

0

Consider the following.

$(function() {
  function updateImage() {
    var newPic = $("<img>", {
      id: "taco",
      alt: "prime.png"
    }).css({
      width: 300,
      height: 300
    });
    var myFile = $("#myFile")[0].files[0];
    var reader = new FileReader();
    reader.onload = function(event) {
      newPic.attr("src", event.target.result);
      $("#hide").empty().append(newPic);
    };
    reader.readAsDataURL(myFile);
    //makeCanvas();
  }

  $("form").submit(function(event) {
    event.preventDefault();
    updateImage();
    return false;
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
  <input type="file" id="myFile" name="filename">
  <button id='submit'>Submit</button>
</form>
<div id="hide"></div>

This reads the file from the input element and renders it as an Image.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this :

function updateImage() {
      circleArray = [];
      newPic = `id="taco" width="300" height="300"  src="${$("#myFile").get(0).files[0].name}" alt="prime.png"`;
      $("#hide").empty();
      $("#hide").append(`<img ${newPic}>`);
      makeCanvas();
    }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda