Hello,
Currently I'm building a Form input which the values will be sent to a Post and Put API.
Now, the problem is, in the API, I have a couple dynamic array inputs.
It will be like this in Swagger:
I'm back again, after some use, I found that the x-www-form-urlencoded can't be used for uploading file, while what I need is sending both the array and the file.
Anyone can help me?
A lot of the specifics are going to depend on your specific API and what it was developed to accept. In cases where I need a more flexible body configuration than what's available with the different types, I've manually constructed a raw body with JS in other cases to get a format the API expects. It sounds like your API is looking for a multipart content type, and then the underlying chunks (separated by an arbitrary boundary you specify) are other content types.
Not the exact same but might get you started, here's an example of an API I was working with that was multipart and accepts a json object and a file in two different parts of the body. I just formatted it for readability using JS templating, and passed in values from components with the ${} syntax. Sounded like yours could use form-data instead of related like mine given your past attempts.
Think manually creating the template string like in my previous post would still have issues with binary files, so adding a more robust solution that leverages the form-data node package now that we can import custom libraries into workflows!
The workflow accepts an array of field or form parts, and uses the package to send the form data customized to whatever the API requires (e.g. a custom part-level Content-Type header). Then the workflow is called from an app with all the necessary fields/files in the payload.