Hey everyone, I’m trying to work with an API that sends PDFs. I’ve managed to get the file in binary format using fetch with authorization. Here’s what I’ve got so far:
Now I’m stuck. How do I turn this binary data back into a PDF? And once I’ve got that sorted, what’s the best way to upload it to Dropbox or Google Drive programmatically? I’m using Code by Zapier for this, if that matters. Any help would be awesome!
Having worked with PDF manipulation in various projects, I can offer some insights. For converting binary to PDF, consider using the ‘pdfkit’ library. It’s quite versatile and integrates well with Node.js environments. As for uploading, I’ve found that Google Drive’s API is generally more developer-friendly than Dropbox’s.
Here’s a rough outline of the process:
Use pdfkit to create a PDF from your binary data.
Set up OAuth2 for Google Drive API.
Use the Google Drive API to upload the generated PDF.
Keep in mind that Code by Zapier has some limitations, so you might need to break this down into multiple steps. Also, be aware of potential memory constraints when dealing with large PDFs. It’s often better to stream the data rather than loading it all into memory at once.
I’ve actually tackled this problem before in a work project. For converting binary to PDF, we used the ‘blob’ approach. Essentially, you create a Blob object from your arrayBuffer, then use URL.createObjectURL to generate a downloadable link. Something like:
As for uploading, I found Google Drive’s API to be more straightforward than Dropbox. You’ll need to set up OAuth2 credentials and use their upload endpoint. The trickiest part was getting the authorization flow right in Code by Zapier, but once that’s sorted, it’s smooth sailing.
Just remember to handle any potential errors, especially around API rate limits. Those can be a real headache if you’re dealing with lots of files.
hey man, i’ve dealt with similar stuff. for converting binary to PDF, try using a library like pdf-lib. it’s pretty straightforward. as for uploading, both dropbox and gdrive have APIs you can use. just make sure you got the right authentication set up. good luck with your project!