Hi all. did anyone get experience dealing with `fi...
# suitescript
n
Hi all. did anyone get experience dealing with
file.create()
with the content getting from
https.response.body
? it's saving a PDF as file.File generated by a suitelet but when doing that, an unexpected error occurs. I assume I was at fault not NetSuite😔 cheers
b
you can try sharing the code, but the usual problem is that the file contents are not base 64 encoded
netsuite uses the content type to determine if it should parse the file contents as utf-8
if the file is not uft-8. like a pdf, the contents are destroyed
n
thanks battk. actually there is `,"Content-Type":"application/pdf; charset=UTF-8",`in the http.reponse.headers so I assume it's UTF8 alr
b
check if the response body is base 64 encoded
your content type is confusing enough that i would not be surprised if its not base 64 encoded
its unlikely that your pdf is utf-8, its a binary file type
n
what I tried so far: 1.convert the response body from UTF8 to base64, it didn't erturn any error but the PDF is empty, ;2 convert the response body from BASE64 to UTF8, an error
BaseEncoding$DecodingException: Invalid input length 15253
occurs
b
you cant convert it back to binary from utf-8
the encoding errors already destroyed the file contents
n
thanks battk. currently i'm managing to find out the encoding of response.body. any advice for that pls?
b
get whoever is generating your pdf to use a content-type of application/pdf
n
it was generated by a suitelet and the type is
application/pdf
weirdfacepalm
b
overwrite the header
the charset is wrong
✔️ 1
n
that makes sense to me now. Thanks a lot battk
you are right @battk. I changed the charset on the suitelet side to base64 like
response.write(nlapiEncrypt(file.getValue(), 'base64'));
and on the client side I directly save the response body as file.File. It works well. You are a legend🖖
b
i meant to use setHeader to set the content type header to your own value