Hi All, I am trying to convert the binary data int...
# suitescript
s
Hi All, I am trying to convert the binary data into an image but I am getting following error - Value of myValue is: {"type":"error.SuiteScriptError","name":"BINARY_DATA_EXPECTED_FOR_SUCH_FILE","message":"You attempted to write non-binary data into a binary file 'TOFNA25000368_qrImage.jpg' of type 'JPGIMAGE'. Binary data must be encoded as base64 strings. You provided the following: �PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000�\u0000\u0000\u0000�\b\u0000\u0000\u0000\u0000>1�]\u0000\u0000\u0013�IDATx^�۲\u0004��$��?=c�!p���y��0kȌk�������\u0004��������\u0003�_u���{[���h0�2�o\u0017�����397�P���N�ɹ�q\u001fl�'����1ϊ�.%gM��\u000f\u000b�.w�\u001c\u0007�3�{\u0010\u000e4ۺYH��\td��\u001f\u0016�]�\"9\u000e�g��)貶R�Ís�6�...","id":"","stack":["createError(N/error)","onAction(/SuiteBundles/Bundle 471956/[WAS]TransferOrderEinvoiceEway.js:870)"],"cause":{"type":"internal error","code":"BINARY_DATA_EXPECTED_FOR_SUCH_FILE","details":"You attempted to write non-binary data into a binary file 'TOFNA25000368_qrImage.jpg' of type 'JPGIMAGE'. Binary data must be encoded as base64 strings. You provided the following: �PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000�\u0000\u0000\u0000�\b\u0000\u0000\u0000\u00001�]\u0000\u0000\u0013�IDATx^�۲\u0004��$��?=c�!p���y��0kȌk�������\u0004��������\u0003�_u���{[���h0�2�o\u0017�����397<��{\u0010\u000e�?�F����|�P���N�ɹ�q\u001fl�'����1ϊ�.%gM��\u000f\u000b�.w�\u001c\u0007�3�{\u0010\u000e4ۺYH��\td��\u001f\u0016�]�\"9\u000e�g��)貶R�Ís�6�...","userEvent":null,"stackTrace":["createError(N/error)","onAction(/SuiteBundles/Bundle 471956/[WAS]TransferOrderEinvoiceEway.js:870)"],"notifyOff":false},"notifyOff":false,"userFacing":false}
b
you probably dont have a choice in this matter
N/file expects the contents to be base 64 encoded
and if they arent already so, you are likely too late to attempt to do so
for example, the contents you currently have is already destroyed by encoding errors, likely from an attempt to encode it as utf-8 text
s
Is there any way to convert binary to base 64?
Somehow it was working earilier 2 months back not sure, how it had worked then.
b
there are if you started with binary, but you rarely actually start with the binary
usually these attempts are from trying to get a response from N/https into the file cabinet
with N/https encoding the content wrong if the content type is wrong
at which point the response is destroyed
if the content type was correct in the first place, N/https would have encoded base 64 in the first place
s
I have given content type as application/json in the api call
b
the content type of the request is irrelevant
N/https uses the content type of the response
s
Any suggestion, what should I try then.
b
if you can manipulate the request to change the content type of the response, you want to do that
else, the unlikely case is convincing the developer of your api to give a better content type than they are currently doing
the final case is getting the file using a service outside of netsuite so that you can then properly get the contents and then upload it the netsuite
s
Thanks, I will ask the API team to provide response in base64. May be, this is their sandbox and it might have issues.
Althought, it is giving the same response in postman and I am able to download the image using send and download button.
b
base 64 would be nice, but thats not actually the option i gave you
s
Then what should be the better content type, anything specific.
IMG_5007.jpg
b
lookup what the content type of a jpg should be
the one they are sending is extra wrong, since it says its utf-8
s
Yeah, what should I ask them to change instead? or how can I manipulate that.
b
164 Views