Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda