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

346
Visualizações
Google-App-Script base64 vs javascript base64 decode

Please, help with GoogleApps Script Base 64 Decode

-- Google Apps Script

  var tmp_base64 = "EXezAAA=";
  var byte_base64 = Utilities.base64Decode(tmp_base64);

  return ContentService.createTextOutput('\''+ tmp_base64 + '\' => \''+byte_base64 +'\'' );

return : 'EXezAAA=' => '17,119,-77,0,0'

-- javascript

function _base64ToArrayBuffer(base64) {
    var binary_string = window.atob(base64);
    var len = binary_string.length;
    var bytes = new Uint8Array(len);
    for (var i = 0; i < len; i++) {
        bytes[i] = binary_string.charCodeAt(i);
    }
    return bytes;
}
_base64ToArrayBuffer('EXezAAA=');

return : Uint8Array(5) [ 17, 119, 179, 0, 0 ]

correctly converted javascript, but why does Google Apps Script convert to wrong bytes?

How to solve this problem ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When the document of "Uint8Array" is seen, it says as follows. Ref

The Uint8Array typed array represents an array of 8-bit unsigned integers.

By this, your _base64ToArrayBuffer returns [17, 119, 179, 0, 0].

On the other hand, at Google Apps Script, the byte array uses "twos-complement 8-bit signed integers" as the default. By this, Utilities.base64Decode("EXezAAA=") returns [17, 119, -77, 0, 0].

This is the reason for your current situation.

For example, when you want to retrieve the same value, in Javascript, please modify it as follows.

From:

var bytes = new Uint8Array(len);

To:

var bytes = new Int8Array(len);

By this, your _base64ToArrayBuffer returns [17, 119, -77, 0, 0].

When you want to retrieve the value of [17, 119, 179, 0, 0] at Google Apps Script, please modify it as follows.

From:

var byte_base64 = Utilities.base64Decode(tmp_base64);

To:

var byte_base64 = [...Uint8Array.from(Utilities.base64Decode(tmp_base64))];

By this, your _base64ToArrayBuffer returns [17, 119, 179, 0, 0].

References:

  • Uint8Array

  • Int8Array

    • When the document of "Int8Array" is seen, it says as follows. Ref

    The Int8Array typed array represents an array of twos-complement 8-bit signed integers.

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