What are the solutions to errors relating to large base64 strings and JSON formatting in the Sendgrid block when using Python to provide an attachment?

This topic was automatically generated from Slack. You can find the original thread here.

I’m running into an issue trying provide an attachment in a Sendgrid block (Send to Single Recipient). To put the data in the right format I have a Python code block before the Sendgrid block that looks like:

def handler(pd: "pipedream"):
  Attachement = [{"content":"<somebase64data>", "type":"application/pdf","filename":"somefilename.pdf"}]
  return {"Attachment": {"data": Attachement}}

This works for small files, but for larger base64 strings that aren’t actually that large (e.g. 200kb) in terms of file-size attachments, the module throws the error

 "Mysql2::Error: Data too long for column 'code' at row 1"

Do you know of any workarounds?

I also haven’t been able to figure out how to feed the appropriate string directly into the Attachments field for the SendGrid Send to Single Recipient block. If I just directly write in [{content:"aGV5",type:"text/plain",filename:"sample.txt"}] as documented beneath the field, the block throws the error Expected property name or '}' in JSON at position 1

Hi Scott, thank you for raising this issue.

I’ve created a ticket here to improve the SendGrid Attachments prop. After the improvement, the action will accept file from tmp dir instead of requiring you to input the base64 content

Thanks!