Are there any modern sendGrid examples with PDF files?

Are there any modern examples of using sendGrid with Wix to send an uploaded PDF file as an e-mail attachment? Everything I can find is from years ago (some when Velo was still called “Corvid”) and no longer works in Wix.

I’m using Wix Editor / Velo.

I’m trying to take a PDF file that the user uploads through a custom form and e-mails it as an attachment. I already have the basic e-mail piece working. It’s not an issue with the SendGrid account or the API key. Email without attachments works flawlessly. How can I extend that to include a PDF from code like:

$w("#uploadButton1").uploadFiles()
     .then( (uploadedFiles) => {
     console.log(uploadedFiles[0].fileUrl); // This is the URL but it's a weird WIX way of doing it.
})

I’ve already tried working with the sendGrid API here: sendgrid-nodejs/docs/use-cases/attachments.md at main · sendgrid/sendgrid-nodejs · GitHub but it really doesn’t work in this case. Wix has all kinds of complaints about that code.

If anyone has code to share, I’d greatly appreciate it.

You could use a Velo Web Method to expose this functionality to the frontend. Your backend function would be your call to sendgrid and the frontend code would call your backend function with the path to the uploaded file.

If sendgrid accepts a URL for file attachments you can use getDownloadUrl - Velo API Reference - Wix.com to get a URL it can access.

Another option is the onFileUploaded event:

Hi Anthony - Thanks for your reply. I am already comfortable with the URL piece; the part that’s unclear to me is using Wix to implement SendGrid’s functionality to convert that URL to an encodable PDF. Their USE_CASES.md from the original post doesn’t do much in the way of useful WIX code.

To clarify the post title, This old topic no longer is valid when I try to work the code into a 2024 Wix site. And this topic is all the way from 2017 but they are asking the same basic question that I am. We’re trying to take a PDF and attach it to a sendGrid e-mail.

If we can find a solution here, I would ask the Wix team to include it in the FAQ write up.
People have been using SendGrid to send file attachments (PDFs / images) for a long time, and it would help to have an example from 2024 in the forums here or in the how-to articles where all the code is up to date. The Wix libraries have certainly updated since 2017 as have the @sendgrid/mail calls – and rightfully so. But because using Velo on Wix isn’t the exact same thing as a pure node.js implementation it’d be nice to see how the two work together on file attachments.

Anyway, Anthony, do you have example backend code that allows the PDF to be sent?

I don’t have such an example available but you’d do something like the following:

You might hit a snag with Buffer, not sure if it works or not. In that case you could also just pass the file URL in the email and then the recipient can click to download the file.

Anyways if you encounter an issue please share your code and the error/what’s going wrong.