dart-lang / http

A composable API for making HTTP requests in Dart.
https://pub.dev/packages/http
BSD 3-Clause "New" or "Revised" License
1.02k stars 352 forks source link

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

Open 1207roy opened 4 years ago

1207roy commented 4 years ago

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

Issue:

Is there any problem with my code?

valehasadli commented 4 years ago

Hi @1207roy, could you share the exact lines, which you’re using.

Note: please use your code statements with "insert code"

Example:

request.fields['documentType'] = 'random types';
request.fields['notes'] = 'xyz';
request.fields['date'] = '2020-05-30';
request.fields['documentName'] = 'abc' 
akbarraihanm commented 3 years ago

same with me here. is this solved?

Manjunath-VM commented 3 years ago

Any Solution For this

neoacevedo commented 3 years ago

To me, I get some fields empty, I don't have a clue why, if I set the values, some of them are null:

request.fields['firstName'] = map['nombre']; // With data
request.fields['LastName'] = map['apellido']; // map has the value, request.fields is null
request.fields['password'] = map['password']; //With data
request.fields['phone'] = map['telefono'];  // map has the value, request.fields is null
hayelom123 commented 2 years ago

for me it only sends the first image

AjinkyaASK commented 1 year ago

This is very weird, there are a lot of people facing this issue (including me), and no one from the flutter community is helping this out!

utkudenis commented 1 year ago

yess, there is a problem in the multipart request.

sebasrod commented 1 year ago

Same thing here, 4 days trying to figure out what I was doing wrong (it wasn't me). I finally had to use Dio, at least while the HTTP team resolves this bug.

ramtinq commented 1 year ago

My server receives empty array of inputs (request.fields) ! This is really weird.

cristianms commented 10 months ago

I'm having trouble with the "await request.send()" part. Apparently the request doesn't even leave the application. I appreciate any help.

Spatino19 commented 4 months ago

I am sending one image file (XFile) from memory along with others fields, but it returns a status code of 400. On Postman it's working properly, and I followed the documentation except that the MultipartFile came from a stream of bytes as opposed to a path.

brianquinlan commented 2 months ago

Would it be possible for someone to include a minimum reproduction?

abdullahalamodi commented 1 month ago

maybe it's related to this one https://github.com/dart-lang/http/issues/159#issue-316963080