【问题标题】:Netsuite Suitescript Decode Base64Netsuite Suitescript 解码 Base64
【发布时间】:2022-10-24 03:57:13
【问题描述】:

我正在与 Suitescript 2.0 进行 Api 集成。从 Api 返回使用 base64 编码的数据。在这里,我需要通过解码 base64 并将返回的 xml 数据保存为 .zip 并解压缩来获取我想要的数据。

相关数据可以在 Notepad++ 中通过 Plugins > MIME Tools > Decode Base64 运行,保存为 zip 并使用 unzip 打开。

我正在使用的脚本是一个 shcedule 脚本。

我尝试了 Suite Answers 中提到的两种解码方法。

1- 从base64到UTF_8,带有N/encode模块(这个问题的返回结果是完全错误的)

2 - 链接中的解决方案: https://netsuite.custhelp.com/app/answers/detail/a_id/41271/kw/base64%20decode

(在此解决方案中,当您将返回的数据另存为 zip 时,打开 zip 时会出现“存档意外结束”错误。)

ArrayBuffer() 和 atob() 在 Suitescript 中不可用。

【问题讨论】:

  • 如果您使用 N/encode 来获取 UTF-8,您实际上看到的是 xml 吗?还是您正在检索以 base64 格式传输的压缩 xml 文件?您的最终目标是什么 - 是将 xml.zip 保存在 Netsuite 文件柜中以供用户打开还是需要处理内容?即你为什么要保存为 zip 文件?只是为了空间——如果是这样,请参阅 N/compress 模块

标签: javascript base64 netsuite decode suitescript2.0


【解决方案1】:

我知道会起作用的是通过某个外部系统上的 Lambda 代理调用。

但是,如果您的数据已经在 base64 中,您可以尝试创建一个文件柜文件,并将 base64 编码值作为其内容。 Netsuite 已经为文件处理 base64,因此您可能会过度处理这个问题。如果您的最终目标是将其保存为 zip,那么听起来您实际上并没有在处理 xml。

如果这无助于查看我的 cmets 关于一些说明的内容,您可以添加到您的问题中。

【讨论】:

    【解决方案2】:
    require(["N/encode"], function(encode){ 
    
     var txt = encode.convert({
                string: "your Base64 string",
                inputEncoding: encode.Encoding.BASE_64,
                outputEncoding: encode.Encoding.UTF_8
            });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多