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

260
Vistas
Is there a fine way to get file mime type / extension by a download link?

I need to get file extension from a download link, currently I'm using the following script (excerpt from React hook)

// ...
useEffect(() => {
    /// ...
    void (async () => {
      try {
        setIsLoading(true);
        const response = await fetch(downloadLink);
        const blob = await response.blob();

        setFileExtension(fileExtensionByMimeType[blob.type]);
      } finally {
        setIsLoading(false);
      }
    })();
  }, []);
// ....

This code works, but the problem is that response.blob() takes time relatively to the file size, and I guess my solution is just bad.

Maybe there is some elegant way to solve my problem?

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

0

My bad, just discovered that I have all the headers I need, I was confused with empty headers prop:

enter image description here

Turns out it's not empty and I can get my mime type by this code:

const response = await fetch(downloadLink, { method: 'HEAD' });
const mimeType = response.headers.get('content-type');

Also, I think HEAD is appropriate here

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