1

I am sending data from a NetSuite Suitelet to the Square Connect API. I am using SuiteScript 2.

I need to send an image file from the NetSuite file cabinet to Square via an HTTP POST. The data needs to be sent as binary data in a multipart form, according to the Square documentation at https://docs.connect.squareup.com/api/connect/v2#endpoint-v1items-uploaditemimage.

I think I've got the multipart form working, thanks to https://stackoverflow.com/a/46964827/127434.

However, I haven't worked out how to get the file data into a binary format that will be accepted by Square. Square complains: "Invalid multipart form data".

I will be happy to receive suggestions.

cja
  • 9,512
  • 21
  • 75
  • 129

1 Answers1

2

I believe file.getContents() returns the base64 encoding for binary files.

So in your mulitpart setup try setting the Content-Transfer-Encoding before the file content data.

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

so in my answer you referenced above you'd try:

if (partIsFile) {
    body.push(getContentType(p.value));
    if(partIsBinary(p.value)) body.push('Content-Transfer-Encoding:base64');
}
bknights
  • 14,408
  • 2
  • 18
  • 31
  • What to do if the `uploadType = resumable`. I uploaded the csv file for this I passed the data directly by reading it from the fileObj as `file.getContents()`.But for other file like pdf,docx it is not working file is getting created but data is stored as a string. – HiddenOne1254 May 25 '23 at 12:33
  • @HiddenOne1254 This would be a whole separate question. – bknights May 25 '23 at 16:30