Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1207roy opened this issue May 30, 2020 · 13 comments

Comments

@1207roy
Copy link

1207roy commented May 30, 2020

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:

  • "request.files" is empty list!!!
  • No image file is received on the server side!!??

Is there any problem with my code?

@valehasadli
Copy link

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
Copy link

same with me here. is this solved?

@Manjunath-VM
Copy link

Any Solution For this

@neoacevedo
Copy link

neoacevedo commented Jun 8, 2021

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
Copy link

for me it only sends the first image

@AjinkyaASK
Copy link

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
Copy link

yess, there is a problem in the multipart request.

@sebasrod
Copy link

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
Copy link

ramtinq commented Jun 14, 2023

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

@cristianms
Copy link

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

@Spatino19
Copy link

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
Copy link
Collaborator

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

@abdullahalamodi
Copy link

maybe it's related to this one
#159 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests