'Unable to send body parameter in Dart/ Flutter multipart request
I m trying to upload image using Multipart request using Dart/ Flutter. but parameter not getting on serverside.
var request = http.MultipartRequest('POST', uri);
request.fields['access_token'] = token;
request.files.add(await http.MultipartFile.fromBytes(
'image', path.readAsBytesSync(),
contentType: MediaType('image', 'jpeg')));
request.headers['Content-Type'] = "multipart/form-data";
request.headers['access_token'] = token;
var response = await request.send();
Solution 1:[1]
It's likely that you're sending an empty payload. From the code snippet you've provided, it's possible that path.readAsBytesSync()
wasn't able to return the File immediately. You can add an await
keyword on your function to wait for the return value before proceeding to send the Request.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Omatt |