Multipart/Form-data call with files

Hi Alumio,

I have a use case in which I have a JSON array of images, with header-data (like filename) and the Base64 encoded images themselves. I have to send this to an endpoint which only support multipart/form-data requests (I can send multiple images in one request).

I have limited experience with multipart/form-data requests, by using the ‘plain text’ option of the HTTP Transformer. However, combined with the fact that I’d have to decode the Base64 to binary, I don’t really see that working in this case.

Is there a way to decode Base64 into binary for an array (with unknown amount of nodes) while sending it within a multipart/form-data wrapper?

Thanks in advance!

Two part question, sending data with multipart/form-data is indeed possible with a plain text body like you’ve tried.

Answer from our dev Ashoka

It is already possible if the fields are known beforehand. Then a plain text body can be sent with placeholders. To generate the body automatically a story is on our backlog.

With placeholders:

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="foo"
&{​​​​​​foo}​​​​​​
-----------------------------9051914041544843365972754266--

Then add header:

Content-Type: multipart/form-data; boundary=---------------------------9051914041544843365972754266

The second part is serializing Base64 to Binary.
I know it’s possible to parse to Binary, but am unsure about serializing.

The thing is that most likely converting the string to binary won’t work anyway.
And it’ll need to create the ‘image’ like a blob and convert that data to binary.
@Alumio_support any options on converting base64 image data to binary image data?

Hi @Alumio_Bot @floris

We just checked that we have a Binary serializer. However, we are currently trying to make it works with an HTTP transformer to submit a file using the multipart/form-data content type. We will get back to you once we figured it out.

Hi @floris @Alumio_Bot

You can decode the array using the mapper “String: Base64 decode” and you can put it in the “plain text” payload. Please have a look at the below exported configurations to decode the base64 encoded binary file within an HTTP transformer.

export_20230526083537.ndjson (13.1 KB)

But unfortunately, the logs of the transformer cannot be displayed at the moment because it has binary in it. However, the request is sent to the server and the image file can be opened correctly.

Please give it try and let us know if you find any problems.

Hi @Gugi ,

Thanks! That’ll allow me to do at least one per call.

Do you think it’s possible to do multiple files per call like this? I mean ‘dynamically’, since I don’t know how many images might be in a call.

I’ve used the &{join( JMESPath before in the plain-text mode, and that works. However here I’d need to encode both the ‘field-headers’ of the Multi-part Formdata as well as the binary data into one field. And I’m guessing that you can’t actually put binary data AND a string into a single field.

Hi @floris

You can actually put binary data and string into a single property. The current problem is Alumio cannot display the property on the transformer test results, transformer test logs, and entity data of a task. So, we suggest you avoid testing the transformer if the output has the binary data in it.

We have just created a sample transformer for you in case you need to upload a dynamic number of images within a single HTTP request. Please have a look at the below configuration. It has test data that has two images within an images array.

export_20230531140634.ndjson (11.0 KB)

Thank you very much Gugi!

My problem was indeed the ‘test results’ window - I hadn’t thought about the fact that Alumio has to render the results in the test-results window and that that’s basicly impossible within JSON for binary data. So I figured it was impossible.

Hi Floris,

We are happy to share the link to the documentation regarding your request: Using the Multipart/form-data with binary data option.

In addition, the feature becomes available in the v3.52.0:

  • in UAT it’s already available;
  • in Production - 23-01-2024.

Please let us know if you have any other questions.