在Google AppsScript中,我正在嘗試使用Utilities
類的Base64 encode一個字節數組。Google AppsScript中的Base64編碼(字節)數組?
UPDATE:的這個例子在這裏:https://script.google.com/d/15eLqgLHExpLG64JZhjUzKfBj4DgLhNZGBOkjwz7AkeeUbcgcaraP4y9X/edit?usp=sharing
// bytes to encode
var toenc = [ 0x52 , 0x49 , 0x46 , 0x46
, 0xBC , 0xAF , 0x01 , 0x00
, 0x57 , 0x41 , 0x56 , 0x45
, 0x66 , 0x6D , 0x74 , 0x20
, 0x10 , 0x00 , 0x00 , 0x00
, 0x01 , 0x00 , 0x01 , 0x00
, 0x40 , 0x1f , 0x00 , 0x00
, 0x40 , 0x1f , 0x00 , 0x00
, 0x01 , 0x00 , 0x08 , 0x00
, 0x64 , 0x61 , 0x74 , 0x61
, 0x98 , 0xaf , 0x01 , 0x00
];
// This errs with -- Cannot convert Array to (class)[]
Logger.log(Utilities.base64EncodeWebSafe(toenc));
// OK, typing issue? Following the doc, but still get same error :-(
Logger.log(Utilities.base64EncodeWebSafe(
Utilities.newBlob(toenc).getBytes()
));
唉,同樣的錯誤不能在運行轉換到數組(類別)[]。
如果我有一個(字節)數組(實際上是一個字符串)數組,我可以使用Utilities
類到Base64嗎?
我可以運行沒有任何問題這一點。輸出結果爲V0FWRWZtdCAQAAAAZGF0YQ == –
AppsScript中的運行無誤嗎? – Xailor
是的,我只是將它包裝成一個函數來運行它,它工作正常。 –