I am creating a web application to read my email messages using the gmail api. All methods work (users.messages.list, users.messages.get, etc.) and are displayed in console.log and on my HTML page. One thing, I noticed that I have to use atob to decode body.data strong> and paste into my HTML. Now I need to download or read the attachment for the file.docx example, and I use this example here after the callback, I noticed that I also need to decode, but if I do this, there is no link to download or read, only some code from the word microsoft If I copy this code and create a document and paste it, it says the file is damaged.
My code is:
function getAttachments(messageID, parts, callback) { //console.log(parts); var attachId = parts.body.attachmentId; var request = gapi.client.gmail.users.messages.attachments.get({ 'id': attachId, 'messageId': messageID, 'userId': 'me' }); request.execute(function (attachment) { callback(parts.filename, parts.mimeType, attachment); }); } if (att.length > 0) { for (var i in att) { getAttachments(response.id, att[i], function (filename, mimeType, attachment) { console.clear(); console.log(filename, mimeType, attachment); console.log(atob(attachment.data.replace(/-/g, '+').replace(/_/g, '/'))); inline.append('<a href="" style="display: block">' + filename + '</a>'); }); } }
UPDATE
I found a solution here
source share