This topic was automatically generated from Slack. You can find the original thread here.
Theo Lemay : Hey, I’m struggling to get this to work. I’m pretty new at node but I’m not sure why this keeps happening. In terms of XY question, I’m trying to download a PDF from a url to attach to a mailgun email. All the info should be in the image, I’ll also include the code here:
Dylan Sather (Pipedream) : awesome. You should also be able to remove the await in front of fs.writeFileSync . Let me know if you’re seeing any other issues
Dylan Sather (Pipedream) : Thanks. Streaming the contents of a URL directly to a file can be useful in situations where you have very large files that exceed the available memory of your workflow (roughly 200MB), but should be unnecessary here. The reason the file looks corrupted is because axios returns a ReadableStream object when you specify responseType: 'stream', so you’d need to handle the response a bit differently. Removing that property and writing the data directly to the file should work.
Dylan Sather (Pipedream) : yeah if this hosting service provides that metadata in the headers, that should be available in response.headers for you to parse. I’m not familiar with the PDF format in enough detail to know whether that would be communicated in other metadata of the file itself, but if so you may also be able to parse the file to retrieve that