You are viewing limited content. For full access, please sign in.

Discussion

Discussion

Posting a PDF to the API appears to add data to the file

posted on June 8, 2023

I tested just the exact example in the documentation with a PDF and after the file arrived it has 16KB of additional data appended to the total file size and Adobe will not open it because it says it is corrupted.

Happens every time, even when testing directly from the rule and uploading a file.

Here is the example I used to create the body

https://developer.laserfiche.com/guides/guide_importing-documents.html

Here is how it looks in my rule

--FakePlasticTrees
Content-Disposition: form-data; name="electronicDocument"; filename="File.pdf"
Content-Type: application/pdf
%(Name: File; Type: File)
--FakePlasticTrees
Content-Disposition: form-data; name="request"
Content-Type: application/json
{
  "template": "Email",
  "metadata": {
    "fields": {
      "Sender": {
        "values": [
          {
            "value": "sender@laserfiche.com",
            "position": 1
          }
        ]
      },
      "Recipients": {
        "values": [
          {
            "value": "recipient@laserfiche.com",
            "position": 1
          }
        ]
      }
    }
  }
}
--FakePlasticTrees

Where did the additional data come from that corrupts the PDF?

0 0
replied on June 8, 2023 Show version history

FYI, this is a rule that we configured which works for uploading a file:

 

With body:

------WebKitFormBoundaryDdk378gdAWuOyaEt
Content-Disposition: form-data; name="electronicDocument"; filename="%(Name: File Name; Type: Text)"
Content-Type: %(Name: Content-Type; Type: Text)
Content-Transfer-Encoding: binary
%(Name: Test File; Type: File)


------WebKitFormBoundaryDdk378gdAWuOyaEt
Content-Disposition: form-data; name="request"

{
  "template": null,
  "metadata": {
    "fields": null,
    "tags": [
    ],
    "links": [
    ]
  },
  "volumeName": null
}
------WebKitFormBoundaryDdk378gdAWuOyaEt--

 

I noticed that a difference is that we have the "Content-Transfer-Encoding: binary".

1 0
replied on June 9, 2023

This was it. I reviewed and compared your body to the one in the documentation and the doc was missing a critical line.

Content-Transfer-Encoding: binary

As soon as I added this, the corruption went away.

I also found that I was missing the last 2 -- characters but this was not the cause of the problem as I fixed this first and it was still corrupted.

Another interesting thing is that your entering the file name into both the URI and the body even though Swagger documentation says it goes into the URI. Although I tried doing this as well and it made no difference.

The real solution was to add this binary encoding line.

1 0
replied on June 8, 2023 Show version history

Hi Chad, could you give us your content type as well?

 

0 0
replied on June 8, 2023

Whenever I've run into an issue like that, seeing what the extra data is has always been very helpful. If you download the document and open it in a binary editor, what is different from what you intended to be there?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.