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

60
Visualizações
Decoding special characters on different file systems with Javascript

I'm trying to figure this out since hours but I simply can't get my head around what is wrong here.

I have a file named test_!§$%&_ÄäÜüÖö.mp4 which I want to upload to an AWS S3 bucket. The upload works fine if there are no special characters (yes I've tried the official answer from the AWS docs by using decodeURIComponnet(filename), but this did not work). I'm not so fuzzed about the special characters !§$%& but I do want the German Umlaute to be converted. Thus I'm doing three things:

// remove all special chars (key comes from the file to upload)
let cleanKey = key.replace(/[°^!"§$%&\\()[\]{}=?*+#<>]/g, "");

// convert spaces to `_`
cleanKey = cleanKey.replace(" ", "_");

// convert German characters
const characters = [...cleanKey].map(char => {

  switch (encodeURI(char)) {
    case encodeURI("Ä"):
      return "Ae";
    case encodeURI("ä"):
      return "ae";
    case encodeURI("Ö"):
      return "Oe";
    case encodeURI("ö"):
      return "oe";
    case encodeURI("Ü"):
      return "Ue";
    case encodeURI("ü"):
      return "ue";
    default:
      return char;
  }
});

// return converted key
return characters.join("");

The problem is that the characters from my file system (MacOS 12.0.1) do not match in the switch statement. I have read a couple of discussions (e.g. here and here) and it seems that character decoding works different on each operating system. Unfortunately I could not figure out how I would convert my filename into a regular UTF-8 string (if this even exists) to parse out the non valid characters?

I know that my approach is probably not really production ready (eg if someone wants to upload a file written in Hebrew letters), so if someone has a better solution for not getting the

The specified key does not exist

error, please let me know.

about 4 years ago · Juan Pablo Isaza
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