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

111
Vistas
Decoding url not working properly JS I tried decodeURIComponent

Hi I have a case a URL simillar to this:

https://linkhere?response-content-disposition=inline; filename="placeholder.jpg"; filename*=UTF-8''placeholder.jpg  response-content-type=image/jpeg&X-Amz-Algorithm=....sometextcontinueshere

I am trying to decode it like this and I need to take the filename

  const decodedUrl = decodeURIComponent("linkhere")
  
  const urlParams = new URLSearchParams(decodedUrl);
  const filename = urlParams.get('filename');
  console.log(decodedUrl) 

But for some reason does not work the decoding properly, do you guys have any idea?

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

0

There is nothing built in that is magically going to get the filename since it is not a querystring paramter. The easiest thing you can do it change whatever is building this to have valid querystring parameters so you can parse it.

With what you have, you will need to read the one parameter that has the file name in it. After that you are going to have to parse out the filename from that string.

Basic idea:

var str = `https://linkhere?response-content-disposition=inline; filename="placeholder.jpg"; filename*=UTF-8''placeholder.jpg  response-content-type=image/jpeg&X-Amz-Algorithm=....sometextcontinueshere`;

const url = new URL(str);
const parts = url.searchParams.get('response-content-disposition').split(/;\s/);
const fileNameParam = parts.find(x => x.startsWith('filename=')).match(/"([^"]+)"/)[1];
console.log(fileNameParam);

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