HTTP Node returns corrupted PDF File (Binary)

Describe the problem/error/question

Hi n8ners,

I am trying to download a PDF document (Invoice) from Lexoffice using the HTTP node.
This is the API document for reference: lexoffice API Documentation

The document is downloaded and no error is displayed, but the PDF document seems to be corrupted and cannot be opened, it throws an error in the PDF viewer in n8n and in every other software as well.

I tried the exact same request in Postman and the response returned the correct PDF document without issues.

The strange thing is that the file size of the response is different as you can see in the screenshots provided. Postman file is 71KB in size, n8n 97KB.

I never experienced that before, so i hope somebody can help out.

Please share your workflow

n8n Screenshots:

Postman Screenshots:

Information on your n8n setup

  • n8n version: 1.49.0
  • Database (default: SQLite): Postgresql
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Debian 11

Hi @denobeno

Could you try to set the N8N_DEFAULT_BINARY_DATA_MODE env variable to filesystem and then see if you can open the file from your local storage?

Hi @ria,

I already tried this as it was mentioned in another issue, but it didn’t help and since the files are very small, this shouldn’t be the issue.

I’ve just tried retrieving a 50MB PDF file from another source which worked fine.

So the file stored on your local was also corrupted and you couldn’t open it?

Since the content-length header is returned by lexoffice, and since the two values do not match, I suspect that lexoffice is returning a different file to n8n.
You could validate this by uploading this same pdf to some other host, and then fetching the file in n8n from that other host instead.

Thanks for your answers and sorry for the late reply.

@ria exactly, outputs are the same in n8n, no matter the binary data mode.

@netroy this is what i already pointed out, the files are definitely different, as you can say by looking at the filesize. I opened both files in a text editor and compared their contents. So there is no need to upload to another host, because the n8n file is already corrupt. I would only fetch the corrupted file again.

The strange thing is that there are no errors, HTTP Status Code 200 in both cases.
Only the Filesize and Connection have different values.

I meant that it’s most likely not the node that is corrupting the file. If you can download the file directly from lexoffice, and upload that to another host, then it’s very likely that that file when downloaded by n8n won’t be corrupt.
The file seem to be getting corrupted before it reaches n8n, and not in n8n, I think.

Yes, that’s what I thought. It’s only a PDF document, and I would have had problems with other documents as well if the node corrupted the data. But just to be sure, I tested if the invoice could be retrieved from another source and it worked fine.

However, this makes no sense as the request is exactly the same and should not give different results.

Changing the connection in the header to ‘keep-alive’ didn’t help either, in postman changing it to ‘close’ still returns the correct document.

So at the moment I am clueless.

The issue has not been solved yet, currently I’m on version 1.51.1.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.