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

294
Views
¿Cómo puedo obtener datos de URL de archivo en javascript?

Intenté usar base64 para obtener datos de imagen:

 function previewFile() { const preview = document.getElementById('video1'); const file = document.querySelector('input[type=file]').files[0]; const reader = new FileReader(); reader.addEventListener("load", function() { // convert to base64 preview.src = reader.result; }, false); if (file) { reader.readAsDataURL(file); } }
 <input type="file" onchange="previewFile()"><br> <video width="320" height="240" id="video1" controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video>

Este script te hace cargar un archivo mp4 y luego lo mostrará.

El problema es que base64 es demasiado largo. ¿Hay alguna otra forma de obtener los datos del archivo pero más corta?

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

0

Desea usar Blob url para src más corto.

Convertir Base64 a Blob

Cambio:

 reader.result

a:

 window.URL.createObjectURL(file) 

 function previewFile() { const preview = document.getElementById('video1'); const file = document.querySelector('input[type=file]').files[0]; const reader = new FileReader(); reader.addEventListener("load", function() { // convert to base64 preview.src = window.URL.createObjectURL(file); }, false); if (file) { reader.readAsDataURL(file); } }
 <input type="file" onchange="previewFile()"><br> <video width="320" height="240" id="video1" controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video>

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!