nodejs gmail api - attachment download url - javascript

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.

Related

Netsuite Suitescript Decode Base64

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

Contents of file not getting decoded correctly even when getting success response in Postman

I am trying below work related to Documentum REST API calls. I believe issue is more towards decoding base64. I think so...
Client application - > Documentum API call to save document
Client application calls API to "create" document -- Works fine.
Client application then calls another API to set contents of file created in step 1.
Document contents is sent as "base64" formatted string (eg - UkVRMDA3NTYwOC8gQ0hHMDA0MDkzNyAgLSB==) to Documentum API - Works fine
Client application fetch document from another API and gets back document with same contents as "base64" formatted string. - Works fine
Now , on step 3 , when i have to fetch document, i want contents to be returned back in utf-8. I tried to decode contents of file ( base64 formatted string) to utf-8 readable format ( format which is actual file content before encoding to base64).
I tried below code as "Test" scripts on Postman and I am not getting any error as such on Postman console.
var CryptoJS = require("crypto-js");
var plainText=pm.response.json().attachments; \\ Taking json response of API call
//console.log(plainText); \\Gives back base64 formatted which was set as document contents
intermediate = CryptoJS.enc.Base64.parse(plainText); \\Doing parse
var response_txt = CryptoJS.enc.Utf8.parse(intermediate).toString(); \\Changing to utf-8
console.log(response_txt);
When i do "Send and Download" on Postman , file is getting downloaded but when i open document I get below error.
"Adobe Acrobat could not open document because it is either not supported file type or file has been damaged (...and wasnt correctly decoded)"
I am not getting what i am doing wrong.
[1]: https://i.stack.imgur.com/FqGP7.png
All I want is when I do fetch document api call to Documentum , I want document to be returned in readable format.
I need guidance like:
Is issue on js script ( as shown above) to decode contents on Postman ?
OR
Is there anything separate I need to do when doing API call to Documentum ?
Thanks
Not sure what you're doing here. DCTM REST will expose a direct ACS link to the content (binary) or provide you directly the file as stored in DCTM, you do not need to do anything with encoding, as you are most likely breaking the file by changing the encoding

Show .tiff/.tif image on chrome from its base64 encoded string with Javascript/Reactjs or convert it to any other (png/jpeg) format and display on UI

I have a base64 encoded string of a .tiff image that I get from the backend. If I decode it and then create a blob url, It works fine on Internet Explorer (by using on src of img tag).
I am not able to show it on Chrome. I have read some answers related to it where people are saying it is not supported on Chrome.
There are some libraries like https://www.npmjs.com/package/tiff-to-png but they require an image to be stored somewhere and then use it to convert. I only have a base64 string of the image. I am not able to find any solution online. My UI is built with ReactJs and backend is on Node.
On backend, I have a buffer of the .tiff image which we are converting to base64 to send it to UI. If we can do anything on buffer, that is also possible. Please help.

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?

Categories