NicoSQ
July 18, 2023, 10:18am
1
I get a .pdf file in a base64 string from a web hook:
Using the SendGrid module, I’m trying to send an email and attaching this file as an attachment.
I’ve tried attaching the base64 I receive as is and I get a corrupted .pdf on in the email.
I’ve tried using the ‘toBinary(;base64)’ function within the email attachment field and I get a .txt file full of random characters in the email.
Any other alternatives or explanations as to why I can’t get the .pdf out the other end?
Thanks!
@NicoSQ The binary data you get is containing the encoding parameter as well. You will have to remove the data:application/pdf;base64, part so it only leaves you with the actual binary data.
Use something like the replace() function for example to do this.
Let me know how that goes.
NicoSQ
July 18, 2023, 10:50am
3
Thanks Bjorn.
Any recommendation on a smart way to do this when the encoding is dynamic? Depending on the file type, this will change.
How can I say "remove everything to the left of the first ‘comma’ "?
Appreciate the help!
@NicoSQ You can use RegEx:
{{replace("data:application/pdf;base64,s87shdfui32nuiwehf8ef"; "/.+base64\,/"; emptystring)}}
In this case replace the static base64 text with the variable you have.
See more about it here:
NicoSQ
July 18, 2023, 12:52pm
5
Thanks Bjorn, the regex worked as expected!
Nonetheless, I now get a .txt file with the entire binary in it:
How can I get this to be the .pdf I’m being sent?
Appreciate the help!
Take a look here @NicoSQ , see if that helps you:
Hey to all you Makers,
So I ask my self how to convert base64 string to binary-file and store on sftp.
[Bildschirmfoto 2022-12-20 um 11.20.06]
I tried it like so. But for some reason the image finally is broken so you can not open.
What ist the problem?
Thanks for you support
Cahore
NicoSQ
July 19, 2023, 9:48am
7
I solved this by adding a ‘.pdf’ at the end of the file name!