Dynamic Length Multipart icon

Dynamic Length Multipart

Send multipart/form-data requests with dynamic JSON fields and binary data

Dynamic Length Multipart

AI-generated

Overview

This node sends HTTP multipart/form-data requests with dynamically defined JSON fields and binary data attachments. It is useful when you need to upload files along with additional form data to an API endpoint that accepts multipart requests. Common scenarios include uploading images, documents, or other files combined with metadata or parameters in JSON format.

For example, you might use this node to:

  • Upload a user profile picture along with user details.
  • Send multiple files with associated descriptions to a content management system.
  • Submit form data and file attachments to a custom API endpoint.

Properties

Name Meaning
URL The target URL where the multipart request will be sent.
HTTP Method The HTTP method to use for the request. Options: DELETE, GET, PATCH, POST, PUT.
JSON Fields A JSON object whose top-level keys become form field names and values become the corresponding field values in the multipart form. Example: { "name": "John", "age": 30 }.
Binary Fields An array of objects specifying which binary data to attach. Each object must have binaryFieldName (the name of the binary property from input) and formDataKey (the key name used in the multipart form). Example: [{"binaryFieldName": "data", "formDataKey": "file"}].
Additional Headers Optional HTTP headers to include in the request, specified as name-value pairs (e.g., Authorization tokens).
Response Type Expected response type from the server. Options: JSON (default), Binary, Text. Determines how the response is processed and output.

Output

The node outputs an array of items, each containing:

  • json:

    • If the response type is JSON or Text, the json field contains the parsed response under response, plus the HTTP status code under statusCode.
    • If the response type is Binary, the json field includes statusCode and headers from the HTTP response, while the binary data is available under the binary property named data.
  • binary (only if response type is Binary):
    Contains the raw binary response data, properly prepared with filename "response-file" and MIME type derived from the response headers or defaulted to "application/octet-stream".

Dependencies

  • Requires the ability to perform HTTP requests with multipart/form-data encoding.
  • Uses n8n helper methods for:
    • Retrieving binary data buffers from input items.
    • Making HTTP requests.
    • Preparing binary data for output.
  • No external API keys or credentials are required by default, but users may add authentication headers via the "Additional Headers" property.

Troubleshooting

  • Invalid JSON in JSON Fields or Binary Fields:
    The node expects valid JSON strings for these properties. Errors like Invalid JSON in jsonFields or Invalid JSON in binaryFields indicate malformed JSON input. Validate and correct the JSON syntax before running.

  • Failed to process binary field:
    This error occurs if the specified binary field does not exist in the input item or cannot be read. Ensure the binary data exists and the field names match exactly.

  • HTTP Request failed:
    Network issues, incorrect URLs, or server errors can cause this. Check the URL, network connectivity, and server availability. Inspect returned error details in the output for more clues.

  • Response parsing issues:
    If the response type does not match the actual server response, unexpected results or errors may occur. Adjust the "Response Type" property accordingly.

Links and References

Discussion