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
httpHandlerin 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-Dispositionvalue (which contains thenameandfilenameattributes 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-datamanually — 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.statusfield isACTIVEas expected.
内容的提问来源于stack exchange,提问作者TMac
相关产品推荐
相关产品推荐

