Problem get PDF

Hi,

I tried use Axios and problem with get a PDF file. With XML file is correct. Where is my error sorry my question I need to use Axios because node http not resolve return of erp api for download files. I believe it is something in the conversion of pdf to base64 I have tried in many ways without success.

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "const axios = require('axios');\n\nconst config = {\n    method: 'get',\n    //url: 'https://www.w3schools.com/xml/cd_catalog.xml',\n    url: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',\n    headers: {},\n};\n\nconst response = await axios(config);\n\n//let fileName = 'cd_catalog.xml';\nlet fileName = 'dummy.pdf';\n\nconsole.log(response.data);\n\n//items[0].binary = {data: {data: new Buffer(response.data).toString('base64'), fileName: fileName, fileExtension: 'xml', mimeType: 'application/xml'}};\nitems[0].binary = {data: {data: new Buffer(response.data).toString('base64'), fileName: fileName, fileExtension: 'pdf', mimeType: 'application/pdf'}};\n\nreturn items;\n"
      },
      "name": "Axios GET",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        190,
        1790
      ]
    }
  ],
  "connections": {}
}

Do not understand. Why do you use a Function-Node with Axios and not the HTTP Request node?

{
  "nodes": [
    {
      "parameters": {
        "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        842,
        336
      ]
    }
  ],
  "connections": {}
}

I try get but not receive file. I try get in Postman with success. My response header Content-Type application/octet-stream, Content-Disposition attachment; filename=“32201011638543000236550020000330271430887396-nfe.pdf”. I try use default node http but return file this image:

When I run the node I did post above it works perfectly fine:


So should it also for you.

Thank you for your help and follow up. Works perfectly with your example but my problem is when trying to connect and download PDF file to another server below the images:



The received binary file does not come in the correct PDF format.

You can try to attach this node after the HTTP-Request node:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "items[0].binary.data.fileName = 'name.pdf'; \nitems[0].binary.data.fileExtension = 'pdf'; \nitems[0].binary.data.mimeType = 'application/pdf';\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        700,
        300
      ]
    }
  ],
  "connections": {}
}
1 Like

I need send Cookie I send this format {{JSON.parse(’{“Cookie”: “JSESSIONID=…”}’)}}

Ok, but do honestly not understand how it relates to my proposed solution. Did you try it? Did it work? How is the cookie related to all of that?

1 Like

Btw. if you need help with this problem please open a new issue. We have to make sure to keep discussions on topic, else it gets very messy and people which have a similar issue will so not find your question and so also not the solution.