You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Karate多部分文件上传请求遭MuleSoft拒绝:‘无法从form-data中获取名称’问题排查求助

Fixing MuleSoft Rejection for Karate Multipart File Upload Requests

What's Going On

That "Unable to get name from form-data" error you're seeing is exactly what the MuleSoft docs hint at: the service expects Content-Disposition headers to be title-cased, but Karate is sending them as lowercase content-disposition, which breaks form-data parsing on the server side.

The Fix

Karate lets you customize request handling with a HttpHandler — we can use this to rewrite the multipart headers to match MuleSoft's requirements. Here's how to adjust your test script:

Updated Karate Test Script

Feature: Multipart Document Upload to MuleSoft API

Background:
* configure httpHandler =
"""
function(request, response) {
  // Grab all parts of the multipart request
  var parts = request.getEntity().getParts();
  for (var i = 0; i < parts.size(); i++) {
    var part = parts.get(i);
    // Get the existing disposition value (includes name/filename details)
    var dispositionValue = part.getHeader("Content-Disposition");
    // Remove the lowercase header and add the title-cased version
    part.removeHeader("content-disposition");
    part.addHeader("Content-Disposition", dispositionValue);
  }
}
"""

Scenario: Upload Document and Validate Active Status
Given url 'https://api.maha.com/documents-process-api/v1/documentC/specialR/documents/'
And header Authorization = 'Basic ' + 'feefff'
And header Accept-Encoding = 'gzip, deflate, br'
And multipart field callingApplicationName = 'Karate'
And multipart file binaryContent = { read: 'response.tif', filename: 'response.tif', contentType: 'image/tiff' }
And multipart field properties = '[{"displayName":"SR Number","value":["1234","12345"]},{"displayName":"Document Type","value":"CLAI"},{"displayName":"Ingestion Source","value":"FILENETTOOLS"},{"displayName":"Received Date","value":"2022-01-14T00:52:50.837650Z"},{"displayName":"Pages","value":"0"}]'
When method Post
Then status 200
And print response
And match response.status == 'ACTIVE'

Key Changes Explained

  • Custom httpHandler in Background: This function runs right before the request is sent. It loops through every part of your multipart form to fix the header casing.
  • Header Rewrite: For each part, we keep the original Content-Disposition value (which contains the name and filename attributes MuleSoft needs) but replace the lowercase header with the title-cased version.
  • Removed Manual Content-Type: You don't need to set Content-Type: multipart/form-data manually — Karate automatically generates this header with the correct boundary value, preventing conflicts.

What to Verify After Applying the Fix

  • Check the actual request details to confirm each multipart part now uses Content-Disposition (title-cased, not lowercase).
  • Confirm the server returns a 200 status code, and the response.status field is ACTIVE as expected.

内容的提问来源于stack exchange,提问作者TMac

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 22:02:39