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

405
Views
El archivo cargado muestra un mensaje de error, ¿cómo resolverlo?

Creé un marcador de posición con una imagen que puede cargar el archivo, luego creo una condición para que el tamaño del archivo recomendado sea de 100 kb o más y menos de 1 mb de tamaño de carga

 var uploadField = document.getElementById("myImg"); uploadField.onchange = function() { // 1000000 = 1MB if (this.files[0].size > 1000000) { alert("File is too big!"); this.value = ""; } else if (this.files[0].size < 100000) { alert("File not recommended size!"); this.value = ""; } }; $('#myImg').change(function(event) { // var tmppath = URL.createObjectURL(event.target.files[0]); $("img#output").fadeIn("fast").attr('src', URL.createObjectURL(event.target.files[0])); // $("#disp_tmp_path").html("Temporary Path(Copy it and try pasting it in browser address bar) --> <strong>["+tmppath+"]</strong>"); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <img src="https://mdbootstrap.com/img/Photos/Others/placeholder-avatar.jpg" id="output" width="100" height="100" style="border-radius: 50%;" /> <input id="myImg" type="file">

Me encontraré con algún error como el que se muestra en el fragmento de código, como si el tamaño es demasiado grande o el tamaño no recomendado aparece algún error

Recibo un error como "mensaje": "TypeError no detectado: no se pudo ejecutar 'createObjectURL' o "mensaje": "TypeError no detectado: no se pudo ejecutar 'createObjectURL' en 'URL': la resolución de sobrecarga falló".,

Por qué está pasando esto ?

¿Cómo puedo solucionar este problema?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

 var uploadField = document.getElementById("myImg"); uploadField.onchange = function() { // 1000000 = 1MB if (this.files[0].size > 1000000) { alert("File is too big!"); this.value = ""; } else if (this.files[0].size < 100000) { alert("File not recommended size!"); this.value = ""; } }; $('#myImg').change(function(event) { if(event.target.files[0]){ // var tmppath = URL.createObjectURL(event.target.files[0]); $("img#output").fadeIn("fast").attr('src',URL.createObjectURL(event.target.files[0])); }else{ alert('Image size mismatched.') } // $("#disp_tmp_path").html("Temporary Path(Copy it and try pasting it in browser address bar) --> <strong>["+tmppath+"]</strong>"); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <img src="https://mdbootstrap.com/img/Photos/Others/placeholder-avatar.jpg" id="output" width="100" height="100" style="border-radius: 50%;" /> <input id="myImg" type="file">

Lo único que debe comprender es que Jquery se activará según los cambios, así que asegúrese de crear un objeto de URL una vez que las imágenes estén disponibles y no sean innecesarias. Simplemente incluya su código en if else y funcionará. Compruebe el ejemplo que se ha modificado según.

about 4 years ago · Santiago Trujillo 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!