【问题标题】:How to get a NetSuite file as a byte array in a SuiteScript 2 Suitelet?如何在 SuiteScript 2 Suitelet 中将 NetSuite 文件作为字节数组获取?
【发布时间】:2019-03-29 16:51:44
【问题描述】:

我正在从 NetSuite Suitelet 向 Square Connect API 发送数据。我正在使用 SuiteScript 2。

我需要通过 HTTP POST 将图像文件从 NetSuite 文件柜发送到 Square。根据https://docs.connect.squareup.com/api/connect/v2#endpoint-v1items-uploaditemimage 的 Square 文档,数据需要以多部分形式作为二进制数据发送。

感谢https://stackoverflow.com/a/46964827/127434,我想我已经让多部分表单工作了。

但是,我还没有弄清楚如何将文件数据转换为 Square 可以接受的二进制格式。 Square 抱怨:“无效的多部分表单数据”。

我很乐意收到建议。

【问题讨论】:

    标签: netsuite suitescript square-connect square suitescript2.0


    【解决方案1】:

    我相信 file.getContents() 返回二进制文件的 base64 编码。

    因此,在您的多部分设置中,尝试在文件内容数据之前设置 Content-Transfer-Encoding。

    https://www.drupal.org/project/smtp/issues/2909678

    所以在我上面提到的答案中你会尝试:

    if (partIsFile) {
        body.push(getContentType(p.value));
        if(partIsBinary(p.value)) body.push('Content-Transfer-Encoding:base64');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      相关资源
      最近更新 更多