dart-lang / dart-lang/http

Multipart form-data request is not working properly. Am i missing something here?

Open
#425 13 comments 16 reactions 0 assignees View on GitHub
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:
![image](https://user-images.githubusercontent.com/58557584/83328954-573a5b80-a2a4-11ea-9fed-c17236e5ee81.png)

# Issue:
- "request.files" is empty list!!!
- No image file is received on the server side!!??

Is there any problem with my code?

Contributor guide

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.