Skip to main content

I have an API that I call to extract certain pages from a PDF. The request seems to be ok. However I get a response in form-data back and I'm stock on how to process. 

< HTTP/1.1 200 OK
< Date: Tue, 01 Oct 2024 14:36:40 GMT
< Content-Type: application/pdf
< Content-Disposition: form-data; name="attachment"; filename="QUERO%20QUERO%201S24_rearranged.pdf"
< Content-Length: 518605

Now I fetch it with @document_data, but it needs treatment to be correct. The previewer cannot read it because probably the content-disposition header should be stripped?

Appears that the whole request isn't accepted. Please TW be a bit clear, or support form-data. I've read all the posts here, chat GPT and everything on google and I really don't  get it working. 

Please explain how I should set up the web connector to do the below API:

https://stirlingpdf.io/swagger-ui/index.html#/General/rearrangePages

I have the document and page range in the database. 


Hello @Freddy,

We do support multipart/form-data through Web connections.

So judging by their API docs, you’ll need to provide three multipart/form-data parameters to the request:

  • fileInput
  • pageNumbers
  • customMode

I'm assuming that fileInput and pageNumbers will require dynamic values and that customMode is an optional parameter that can typically be skipped. So we will need two input parameters on our Web connection:

 

Your endpoint configuration should look like this:

Again, I have not added a form field for the customMode parameter, because I'm assuming that it is optional.

Now you will need to supply values for the fileInput and pageNumbers parameters in the corresponding Web connection process action. To do this, you will need two process variables:

  • fileInput - This should be a VARCHAR(max) because the API docs state that the parameter is a binary string. I'm assuming that binary string means base64 encoded binary string, as this is typically how this works in APIs, but it's hard to be certain, the API docs are not clear.
  • pageNumbers - This should be something like VARCHAR(100) to allow for various page range expressions like ‘1, 2-5, 7, 8’.

These parameters can simply be hooked up to the input parameters of the Web connection process action.

Now you will most likely need a task that allows you to upload a PDF document and enter the page range. The easiest way to do this is to use a database file storage location on your task with a VARBINARY backing task parameter for the PDF upload. All that's left to do then is to convert the VARBINARY to a base64 string and assign it to the fileInput process variable. Which you can do like this:
declare @pdf_data varbinary(max);

SELECT CAST('' AS XML).value('xs:base64Binary(sql:variable("@pdf_data"))', 'VARCHAR(MAX)')

I think that this is how the request should be set up, can you check if this request is accepted by the web service? If so, then we can continue this topic on how you need to process the response. For that part it would be helpful to have an example of what the response looks like, as the API docs are extremely limited in this regard.

I hope this helps.


Thanks @Vincent Doppenberg, give me some time to actually test it and come back to you. 


@Vincent Doppenberg I have another local API running also with form-data, and also this one I cannot get to work. This one has a UI in front of it and I see that the payload is:

 

 

I created a web connection and added the form field. 

 

The error I get is "Bad request: file not found.”

I've tried to base encode them and also not ( I don't think it's needed). 

However does de web connection add the filename behind the name? And how does content-type work? 

 

Their documentation:

 


Hi Freddy,

I am afraid this isn’t possible with the WebConnector right now. It does support multipart/form-data, but it is not possible to set the “filename” and the “Content-type” per form field.

It seems that for this scenario, the HttpConnector provides more control - because it is possible to provide raw data for the content.

In the following topic you can find more information how it can be done. Erwin provided some nice sample code to make it work:

sending a pdf with the http connector | Thinkwise Community

Note that the process variable used for the content is a varbinary(max).

 


Hi Freddy,

I am afraid this isn’t possible with the WebConnector right now. It does support multipart/form-data, but it is not possible to set the “filename” and the “Content-type” per form field.

It seems that for this scenario, the HttpConnector provides more control - because it is possible to provide raw data for the content.

In the following topic you can find more information how it can be done. Erwin provided some nice sample code to make it work:

sending a pdf with the http connector | Thinkwise Community

Note that the process variable used for the content is a varbinary(max).

 

Thanks for the reply, not really the answer I was looking for to use a HTTP connector with crazy code to 'make it work'..  @Arie V this should be on the radar. Form-data is not a very uncommon type and should be supported out of the box imho.  


@Freddy I'll make sure to discuss soon with the team on how we can do some quick improvements on the Web Connector documentation and/or functionality. It's clear that it's not that easy to work with at the moment.

There are bigger plans to simplify integrations, but that's not a short-term priority for 2025 H1.


Reply