Netsuite Suitescript Decode Base64 - javascript

I'm doing Api integration with Suitescript 2.0. A data encoded with base64 is returned from the Api. Here I need to reach the data I want by decoding the base64 and saving the xml data returned as a .zip and unzip it.
The relevant data can be run in Notepad++ with Plugins > MIME Tools > Decode Base64, saved as zip and opened with unzip.
The script I'm working with is a shcedule script.
I tried the two methods mentioned to decode in Suite Answers.
1- From base64 to UTF_8 with N/encode module (Returned result is completely wrong for this problem)
2 - The solution in the link:
https://netsuite.custhelp.com/app/answers/detail/a_id/41271/kw/base64%20decode
(In this solution, when you save the returned data as zip, it gives an "Unexpected end of the archive" error when opening the zip.)
ArrayBuffer() and atob() are not available in Suitescript.

The thing I know will work is to proxy the call through a Lambda on some external system.
However if your data is already in base64 you might try just creating a file cabinet file and give it the base64 encoded value as its content. Netsuite already handles base64 for files so you might be overworking the issue. It doesn't sound like you are actually processing the xml if your end goal is to save it as a zip.
If this doesn't help see my comments regarding some clarifications you could add to your question.

require(["N/encode"], function(encode){
var txt = encode.convert({
string: "your Base64 string",
inputEncoding: encode.Encoding.BASE_64,
outputEncoding: encode.Encoding.UTF_8
});
}
SuiteScript example
All types of encode

Related

nodejs gmail api - attachment download url

so i got the attachment id from the api, and the payload is data in bytes
from https://developers.google.com/gmail/api/v1/reference/users/messages/attachments#resource
The body data of a MIME message part as a base64url encoded string.........
so i tried decoding it with https://github.com/brianloveswords/base64url
and few other base64 plugins - all returing another unreadable string format.
since i wasn't sure if it was an actual file or decoded url i tried exporting contents to a file with known extension without much success, so it should be a download link.
does anyone have any idea how to get a readable format of this string?
payload string sample
1op669AzYx7c9caYxOd0ZWzNE7IqPyUUnmRkib4HPAUbc3FzzEs7xWl6glqXXo2Y_hjSfT9CtS0THzTkf2rZ8UbKU6S
base64 utf8 decoded sample
↑8�k垬☼A��VN��\�>�/i��U�ՁR∟F����A�☺ň<�v¶��C� I-t��]⌂�R☺
string is much muh bigger, testing can be done here for full response https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get
UPDATE
Solved it
https://stackoverflow.com/a/16350999/7579200
Sounds like you should use the get function.

Python Requests PDF Content

I am having trouble finding the answer I need for my situation and hoping that someone may be able to help.
Full disclosure, I am pretty new to Python.
What I am trying to achieve is;
Perform a HTTP POST to download a PDF (with Requests, Python 3).
I want to take the stream and give it Google Drive, which will convert back to a PDF and save the file in the Drive folder.
I am ok with the url file request, but I am receiving UnicodeDecodeError on reading the contents. I have tried several files but the same result.
The limitations I have are that I can't install packages (limited to the couple that are provided) and cannot write the output to a file (read-only fs), as I am using Zapier.
This is the (very) basic code I am using;
import requests
url = 'http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf'
resp = requests.get(url, stream=True)
resp_bin = (resp.content)
return {'output': resp_bin}
Note that the file is just a random file I found for testing purposes.
Error received is; UnicodeDecodeError: 'utf8' codec can't decode byte 0xe2 in position 10: invalid continuation byte
If anyone has a way of making this work without additional packages, that would be great.
Note: I do also have the option of urllib here and alternatively JavaScript (node.js v4.3.2) with fetch.

js, jquery image to JSON -> JSON to image

I am probably puting a bad query to google however i can not find proper solution.
I have an mobile app (client) that would allow admin to load images from server. Because all the data from server comes via JSON file, my idea is convert on server side an image to json object (ie with help of base64). Using this solution i might get multiple images and additional data in one JSON file. Later i would inject b64 encrypted image to image via javascript in mobile app.
I can also use jquery.
The questions are:
do i need encrypt image to base64 before changing it to json? (i'd do that via php). i guess i need to do this because of escape characters in pure image files.
how to decrypt from base64 to json/string variable in javascript/jquery?
how to put binary image (decrypted from base64) to an image. Ie vie var img = new Image()
Any answer to this questions would be appreciated.
Or maybe there is a better solution?

JavaScript convert UTF-8 written data to ISO-8859. (Don't think URL/HTML context, but data file context)

I am currently creating a CSV as a downloadable attachment that gets attached to a record in a table. The framework itself just writes the data content in UTF-8 into the created file. It doesn't give me an buildin tool to chose another encoding. What JavaScript options do I have to encode the output stream written into the attachment with ISO-8859-1 instead of UTF-8?

How to save a file from a URL in Parse.com using Javascript

I know the syntax for saving files in Parse.com (https://www.parse.com/docs/js_guide#files-classes), but now I have a URL instead of a local file - http://graph.facebook.com/{FacebookID}/picture, how can I save it in Parse? Thanks!
You can't create/save a Parse File with the contents of a remote file, only data you have locally (like a base 64 encoded string, or a byte array, etc.)
See the Parse File (JavaScript) docs here: https://parse.com/docs/js_guide#files

Categories