cancel
Showing results for 
Search instead for 
Did you mean: 

Send Document using Multi Part Form Data in Web API

AmbrishSrivasta
Level 2
We are trying to consume a webservice which take a document and other metadata using multi part form data Content Type.
We are able to call the service successfully using Postman, but when using Web API feature of Blue Prism latest version 6.5 we are having following observations.
1. When using Template dropdown option in the Request, it is sending the whole data in json format instead of multi-part form data as expected by the service.
2. When using Single or Multi File option, we do not see a way to send additional attributes in the body as expected by service
3. We also wrote a custom code to send the information using multi-form, but even that ended up sending information in raw format.

Any experience on above requirement?

------------------------------
Ambrish Srivastava
Architect
Persistetnt Systems Inc
America/New_York
------------------------------
37 REPLIES 37

Hi Bimal,

Many thanks for sharing this.

I am still having a few issues trying to send a multipart/form-data POST request.

What variable type is your [fileValue] parameter?

Thanks,
Harrison

------------------------------
Harrison Jardine
Consultant
Protiviti
Europe/London
------------------------------

Hi Harrison,

File value is the actual Binary data for the file. The blue prism process that call the multipart/form-data api will extract the file in a binary format using file system vbo and pass it on here

------------------------------
Bimal Sebastian
Consultant
Blueprism
Asia/Kolkata
------------------------------

Hi Bimal,

When sending the file using Binary I am unable to open it on the target system as I think it is getting corrupted in some way. They have asked if I can send the file using a Byte Array.

Is this possible using the approach above?

Thanks,
Harrison

------------------------------
Harrison Jardine
Consultant
Protiviti
Europe/London
------------------------------

@Bimal Sebastian,

I'm attempting to setup the API endpoint to upload a file, it works in Postman, but when I am trying to set it up in Blue Prism I'm having some issues, I've attempted to recreate what you have in the image but what should the boundary be? Filename should of course be the file's name, and filevalue should be the binary data I'm assuming.

Thank you for your help,

Tracy


------------------------------
Tracy Schultz
------------------------------

@Tracy Schultz 
The boundary is any arbitrary character. As a matter of fact it can be hardcoded as well if you chose to. Most api end points dont care what the boundary is, as long as there is a boundary.
To be more elaborate, Boundary is a http protocol requirement. This essentially is a way to tell where a particular "part" in a "multi-part" form begins and end.

------------------------------
Bimal Sebastian
Consultant
Blueprism
Asia/Kolkata
------------------------------

@Bimal Sebastian

Looking in Postman at the headers needed for the API it has ​the following needed headers. Can you shed light on what headers are included as part of the API integration for sending files or file for the body of a POST?

We can easily get the number of bites using a calculation and we can set the Content-Type header easily, however is Content-Length sent automatically or can we set it? Knowing what headers are sent or possible to send would be helpful. If needed I can include the Request Headers and Request Body from postman where it worked minus authentication items.

Content-Type: multipart/form-data; boundary=--------------------------757794703188956163047914
Content-Length: 1179190

Any and all help is much appreciated.

Thanks,

Tracy

------------------------------
Tracy Schultz
------------------------------

Think I'm starting to understand. Looking at the raw log from Postman I'm seeing the following.

Content-Type: multipart/form-data; boundary=--------------------------035755082283824938336703
Content-Length: 1179190
----------------------------035755082283824938336703
Content-Disposition: form-data; name="file"; filename="1718367-2019-1231-MID; 1040.pdf"

<1718367-2019-1231-MID; 1040.pdf>
----------------------------035755082283824938336703--

So would I want this as the body template?

[boundary]
Content-Disposition: form-data; name="file"; filename="[filename]"

[filedata as binary]
[boundary]--

And if so then add these headers to the action?

Content-Type: multipart/form-data; boundary=[boundary]
Content-Length: [length of file binary]

Apologize for all the questions but I feel like I'm on the edge of understanding.



------------------------------
Tracy Schultz
------------------------------

Ok I've set this up as my template.

Content-Length: [Content Length]
[Boundary]
Content-Disposition: form-data; name="file"; filename="[File Name]"

[File Data]
[Boundary]--

I've also added these headers

Content-Type multipart/form-data; boundary=[Boundary]
Cache-Control no-cache

When I run it I'm getting this error.

Unexpected error Error during Web API HTTP Request
HTTP Status Code: 400
HTTP Response Content: {"key":"ERROR_HAS_OCCURRED","value":"Unexpected end of MIME multipart stream. MIME multipart message is not complete."}

Here's what I have from Postman.

Cache-Control: no-cache
Host: api.thomsonreuters.com
Content-Type: multipart/form-data; boundary=--------------------------035755082283824938336703
Content-Length: 1179190
----------------------------035755082283824938336703
Content-Disposition: form-data; name="file"; filename="1718367-2019-1231-MID; 1040.pdf"

<1718367-2019-1231-MID; 1040.pdf>
----------------------------035755082283824938336703--

Not seeing what I'm getting wrong on this.



------------------------------
Tracy Schultz
------------------------------

Ok looking into it when I try to send the data as binary is when I get a 415 error. Is there a way to send a file in BP that doesn't require me to convert the file to binary first?

------------------------------
Tracy Schultz
------------------------------

This is the structure of my collection:
26445.png

I use a calculation stage to read the file to binary, and store in the collection "File" field:
26446.png




------------------------------
Chris Hogan
Senior Ecosystem Architect
Blue Prism
------------------------------