Hi coders
since " request-promise" is not working any more, can someone update the code, how to use it with " node-fetch" or alternatives as recommended in the following post:
https://www.wix.com/velo/forum/coding-with-velo/file-attachment-using-sendgrid-api
I am still not familiar with this concept and don’t know what result I need for starting base64 encode
Thanks for your help guys!
j Florian
import sgMail from"@sendgrid/mail";
import request from"request-promise";
import encode from"nodejs-base64-encode";
const apiKey ="SG.XXXXXX";//api key//pass the url of the file from the page. It should be the entire url and not just the url you get after uploading the file using .startUpload()
export function mailing(url){//read above
return request.get(url,{encoding:null})
.then(function(res){var base64File = encode.encode(res,'base64');
return sending(base64File);});}
function sending(base64File){ sgMail.setApiKey(apiKey);const msg ={
to:'test1@gmail.com',
from:'no-reply@gmail.com',
subject:'Hello attachment',
html:`<p>Here’s an attachment for you!</p><br> <br> Thanks`,
attachments:[{
content: base64File,
filename:'My_PDF.pdf',//replace dynamically if needed
type:'plain/text',
disposition:'attachment',
contentId:'mytext'},],};
return sgMail.send(msg)
.then(function(err,
response){if(err){return err;}return response;})
.catch((err)=>{return err;});}