cancel
Showing results for 
Search instead for 
Did you mean: 

Rest Post multipart/form-data

nativeBasic
New Contributor III

Hello,

I am trying to upload a file to a REST POST multipart/form-data web service without having to initially create the file onto the SLDB.

The web service works fine when payload.xml has already been created onto the SLDB.

Screenshot 2023-12-20 at 16.28.16.png

The web service wants a multipart/form-data POST.  

When I have tried mapping $content, I seem to be missing the filename attribute in the content-disposition.

Can anyone suggest a way to achieve this?

 

4 REPLIES 4

nativeBasic
New Contributor III

Some further information.

Below shows the response when the file 'payload.xml' is uploaded from the SLDB:

Screenshot 2023-12-21 at 15.42.37.png

Within the boundary I can see the filename attribute:

Screenshot 2023-12-21 at 15.43.06.png

However, when I try writing the file directly to the endpoint:

Screenshot 2023-12-21 at 15.43.59.png

What I noticed is the filename attribute cannot be set and perhaps the reason the endpoint is not 'seeing' the file...?

Screenshot 2023-12-21 at 15.45.50.png

Does anyone have any experience of multipart form-data? 

koryknick
Employee
Employee

@nativeBasic - I do pretty well with the HTTP Client to call most APIs but I've only ever used a pre-existing file to post to a multi-part form.  If you don't want to use the SLDB to write the file and have to worry about cleaning it up, you could write the file using the pipe.tmpDir build-in property.  This is a temporary directory that only exists while your pipeline is executing; as soon as the pipeline completes (success or failure), the directory and all contents are automatically purged.  This should also be faster than SLDB and doesn't have the 100MB file size restriction imposed by the SLDB.

Hope this helps!

nativeBasic
New Contributor III

The file itself is a financial transaction file so only a secure S3 seems to be acceptable by the client, however the HTTP Client does not support S3.

Thank you, I will look into the pipe.tmpDir suggestion. An alternative would be to create the file onto our groundplex which I believe the snap does support.

Ideally I would have liked to stream the $content but believe it is the filename attribute which is omitted by the snap when the option of 'TEXT' is selected that maybe the issue.

This is sample python code that looks to add the filename attribute within the boundary. 

Screenshot 2024-01-04 at 13.59.14.png

This might be a limitation of the HTTP Client or the endpoint we are using. I don't believe there is any reason why the filename attribute couldn't be added within the boundary if it were needed, but I am not strong on this topic so unsure.

nativeBasic
New Contributor III

As an update I have been informed by snapLogic that this is a limitation of the HTTP Client snap and that there is an enhancement request in place.

In the meantime I have used the pipe.tmpDir which works fine!