Received a raw image data from a server request (l...
# suitescript
h
Received a raw image data from a server request (like screenshot below). How can a backend Suitelet display the image or view the document?
b
N/https does not handle binary well
all those � characters are encoding errors from an attempt to convert to utf-8
you cant actually reverse that because the encoding error doesnt actually represent the binary content
🙌 1
generally your only chance for working with binary data is receiving an encoded version of it, usually base 64
generally netsuite only does that when the content type header on the response is correct
h
Oh I see, thank you! So it's more of a limitation of https.get huh. If the server can't send base64, any alternative you have for doing an http request?
b
if the server correctly sets the content type header, netsuite may do the base 64 encoding for you
otherwise you will need to do at least part of your code outside of suitescript on another application server
h
Yes looks like it. So basically a custom module where all it does is do an http get request without using the https module.
b
as in you do logic outside of netsuite
where you have more control
h
Oh I see. Would you have any samples or documentation? I only know NetSuite tbh
I'm seeing fetch as alternative. Just not sure how I can integrate it with NetSuite as it looks to work only on client side.
b
you have effectively learned javascript wrong if you only know it through suitescript
usual answer is to pick your favorite programming language and use whatever application server it offers
if the answer was javascript, that usually means nodejs
🙌 1
h
Gotcha I'll look into it. Thanks!!
b
the other approach is to use one of the many cloud based integration that try to simply integration tasks
h
I'm looking into nodejs now. I'm able to connect to to the server using https.get of node. Now I just need to know how my NetSuite Script can call this.
b
depends on what your design is
you can setup a web server on node js so that you can send requests to it from netsuite using N/https
or you can start from nodejs and make requests from node js to netsuite
h
I just did NodeJS. So here's what happened N/https.get -> Receive binary data -> Base 64 value NodeJS https.get -> Receive binary data -> Base 64 value And they both had the same base64 value. The only application who can correctly render the image is Postman.
b
What did the node code look like
h
message has been deleted
Do you think Blobs could receive the N/https.get response and convert it to base64 instead?
b
your data callback is implicitly using .toString, chunk is not a string
h
whats a better way to represent that as to a base 64?
b
you cant do the encoding until you have all the data
h
gotcha thank you so much!