Flutter:

var request = new http.MultipartRequest("POST", url);
request.fields['name'] = 'John';
request.files.add(http.MultipartFile.fromPath(
    'file1',
    '/path/to/file1.jpg',
));
var response = await request.send();

On server side java servlet:

 request.getParts();

throw exception:

java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
        at org.apache.catalina.connector.Request.parseParts(Request.java:2866)
        at org.apache.catalina.connector.Request.getParts(Request.java:2834)

request.getContentType() is correct, returning "multipart/form-data; ...".

1

There are 1 best solutions below

1
Hardik Mehta On

You have to add await before http.MultipartFile.fromPath

var request = new http.MultipartRequest("POST", url);
request.fields['name'] = 'John';
request.files.add(await http.MultipartFile.fromPath(
    'file1',
    '/path/to/file1.jpg',
));
var streamedResponse = await request.send();
var response = Response.fromStream(streamedResponse);

You should be getting at servlet side after this change.