Multipart form-data request is not working properly. Am i missing something here?
- Dominant language
- Dart
- Stars
- 1.1k
- Forks
- 419
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 8
Description
I am trying to send a multipart form-data request in flutter using http package
# Code is as below:
**//request**
var request = http.MultipartRequest('POST', Uri.parse(uploadDocumentsUrl));
**//add header fields from requestHeader map**
request.headers.addAll(requestHeader);
**//add fields**
request.fields['documentType'] = 'random types';
request.fields['notes'] = 'xyz;
request.fields['date'] = '2020-05-30';
request.fields['documentName'] = 'abc'
**//add image files, File imagefile1, File imagefile2**
request.files.add(http.MultipartFile.fromPath('file1', imagefile1.path));
request.files.add(http.MultipartFile.fromPath('file2', imagefile2.path));
**print('request files: ${request.files}); //it prints an empty list**
**//final send the request**
var response = await request.send();
**//check result status**
print('response code: ${response.statusCode}');
**//get data**
String jsonString;
await response.stream.transform(utf8.decoder).listen((value) {
jsonString = value;
});
# Postman screenshot:

# Issue:
- "request.files" is empty list!!!
- No image file is received on the server side!!??
Is there any problem with my code?
Contributor guide
Research direction
Start by reproducing the request with http.MultipartRequest, request.fields, and MultipartFile.fromPath using the code shown. Check whether request.files is populated before send() and whether the server receives the files; done means the multipart request works for the reported fields and files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100