How to send multiple files in attachment of FormData multipart

I want to send multiple files using the attachment form data attribute. I have brought up this problem before, but in that topic, we could only pass one file. Now i have to send multiple files as a single attachment.
Kindly refer to the below topic for better understanding and to get the data:


{

"data":{
"subject":"Chalking",
"attachments":[
"20230906_1693987303774.jpg",
"20230906_1693987356111.jpg",
"20230906_1693987371073.jpg"
],
"description":"testing attachment",
"email":"[email protected]",
"priority":2

}

Hi @Farheen_I :wave:

I might be misunderstanding as your example workflow relies a lot on data that we can’t use to reproduce, but could you use a Split in Batches node here in order to upload the files one by one?

Hi @EmeraldHerald , Here is the code that I want to reproduce.

Here, I want to use Form-Data to send multiple images in one attribute of an attachment. The problem with this is that it only sends the image name, not the image’s file format.
Below is screenshot of my application , how it is visible when i am downloading the myFile.txt
Screenshot 2023-09-08 at 4.24.19 PM

The expected output should be like this:

Would this be closer to what you’re looking for, or perhaps put you on the right track? :thinking: It’ll split your attachments into three separate files called data, and then try to upload the data (along with your other fields) through the HTTP request.

1 Like

No, it is not operating. After adding the attachment array, the HTTP node throws the error shown below.


Hi @Farheen_I :wave: Can you try an expression like {{ $("mapping data").first(0, 0).json.data.custom_fields.depot_name }} (going by what’s in your screenshot), and seeing if that works?

Hello, @EmeraldHerald Unfortunately, it still does not work.


Can you try not using $(node), but $('mapping data') in all fields?

Yeah ! Thank you, @EmeraldHerald, it worked. You are fantastic! :giggling
However, I am still in a bind because the attachment we send with the formdata does not update inside of a single array. Multiple tickets are created for each attachment, and each attachment is sent separately. It should proceed as follows:


You can refer to this screenshot below for more clarification of workflow. The output of HTTP node should be 1 item

Hi @Farheen_I - the HTTP node unfortunately wouldn’t support this in the way you’re looking for :see_no_evil:

A way to go about this would be to create the ticket in Freshservice previous to trying to upload an attachment (to avoid four separate tickets being created), and then update the single ticket with each attachment one by one as a workaround.

If this fails because Freshservice’s API does not allow for these four items to be uploaded to a single ticket individually, the only other workaround I can think of would be to zip these four attachments and upload that singular file. If you’re self-hosting n8n and you’re handy with cURL, you could also use the Execute Command node as a workaround, too.

I’ll move this over to the feature request section of our forums so that our product team gets their eyes on multiple attachments in a single field sent through one HTTP Request node request :bowing_man:

2 Likes

okay @EmeraldHerald ! Thanks for your support. :grinning:

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.