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



Web Request Rule - POST LF Cloud file to Web API

asked on October 15, 2022

Hi all,

We are working in Cloud with an API that will happily accept general GET and POST of text-based JSON content. But we're having significant issues trying to get a file uploaded to the API using Content Type of multipart/form-data.

Here's the config of the Web Request:

And here's the Test Web Request screen when we select a document from the local device's drive:

So far, so good... it all looks ok.

But after running the test - we get the following:

Despite saying it was run successfully; the server response is a 500. Which is a generic 'Internal Server Error'.

If we do the exact same thing in the target system's Swagger, with the exact same file, and exact same API Key - we can post to the exact same API Endpoint successfully.

Working with the developers for the other system, they are unable to see any log or provide any response content. If we run this using a workflow, we just get a 'false' success status for thye call, and no content - so we can't even see what might be the issue. It's as though LF CLoud is not even making the call.

If anyone can see anything wrong with the config above - or anything I might be missing; please let me know - that would be great - thanks!

0 0


replied on January 16, 2023

Just as an update to this - we resolved this issue and thought I'd share the resolution for anyone finding this page.

The above pic is to a different API than the previous one; but the correct formatting is still the same. Here is the full 'Content Body':

Content-Disposition: form-data; name="%(Name: FileName; Type: Text)"; filename="%(Name: FileName; Type: Text)"
Content-Type: application/pdf
Content-Transfer-Encoding: binary

%(Name: InvoiceFile; Type: File)

Using the above formatting works well.

0 0


replied on October 17, 2022

That 500 error is from target website to web request rule container, but the rule somehow didn't detect it as an failed execution.


As for the error itself. Swagger uploader may set some default sub-content parameters which are missed in the rule configuration but required by the target web site?



Content-Disposition: form-data; name="fileName"; filename="file3.jpg"

Content-Type: image/jpeg

Content-Transfer-Encoding: "BINARY"

[file content goes there]


Specially rule container also use [Content-Transfer-Encoding: "BINARY"] to decide sending the file in Binary format or Base64 string format.


So you probably want to try the rule config like:


Content-Disposition: form-data; name="fileName"; filename="file3.jpg"

Content-Type: image/jpeg

Content-Transfer-Encoding: "BINARY" (or "Base64" if target website expect base64 string format)

%(Name: Upload_File; Type: File)







1 0
replied on October 17, 2022

Hi Kern - thanks for the suggestion - really appreciated.

However - when I try manualy editing the Content Body to include your other parameters, we get different errors.

Either we get:

Unpexected Token Type DQuote, expected: Text

We never get to a result page, so this is Laserfiche refusing to even make the call. I believe this happens when we add quotes around some of the parameter values (e.g. "BINARY"). Removing the quotes the call is made, but we still get the 500 error.

Or we simply get the same 500 error - no matter how we change the construction of the content.

If it helps - the Swagger Curl looks like this:

curl -X POST "https://*******************/api/Attachments/Temporary" -H  "accept: application/json" -H  "Authorization: Bearer eyJhbGciOiJ*************************************************************************************************************************************" -H  "Content-Type: multipart/form-data" -F "file=@1234 - TESTING Daily Plant Pre-Start Checklist 10_16_2022 1_44_22 PM.pdf;type=application/pdf"

Does that give you any pointers as to how the Content Body should be constructed?

Thanks again!

0 0
replied on October 17, 2022

My example code is wrong. Content-Transfer-Encoding value should NOT be double quoted.


Content-Transfer-Encoding: "BINARY"


Content-Transfer-Encoding: BINARY


This is the only property that would affect the rule container's behavior itself (control the upload file format). Other than this one, rule container just forward all properties literally.


I can't tell what's missing from the curl log. Swagger maybe a little tricky, have you tested the target API server from other client tools, e.g., PostMan?

1 0
replied on October 17, 2022 Show version history

Another debug tools would be [Postman Echo] as a server side replacement.


You can config a same web request rule just replace the host from your target website to [Postman Echo]. The [postman echo] would return all the information the client sent to itself.


Then you can use a postman client cfg (assume it succeed on target website) to send same request to [Postman Echo] and compare the two requests.

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

Sign in to reply to this post.