0
votes

I have to send, via https.request, a PDF file, but I only have the Base64 content and the only format that the server accepts is the byte array.

In JavaScript, on the client side, that's very simple (UInt8Array and Blob) but those are not implemented in NetSuite so I can't use them. Is there any alternative way to do that without using UInt8Array or Blob?

I compose the body of the multipart/form-data request and in the body I decoded the Base64 to a UTF-8 string but it doesn't work, it sends the file correctly but is empty.

The format that I need is application/octet-stream.

1

1 Answers

0
votes

Try using the following function to convert to Uint8Array:

function stringToUint8Array(input) {
    var out = new Array(input.length);
    for (var i = 0; i < input.length; i++) {
        out[i] = input.charCodeAt(i);
    }
    return out;
}

It might screw up some characters though, I have never tested it for that purpose. I used it for a compression library I reverse engineered to work serverside and it worked.