var uri = Uri.parse('https://www.baidu.com/upload');
//创建请求
var request = http.MultipartRequest("POST", uri);
//添加请求参数 (参数名和参数值,必须为String。int也不行,必须转成String)
request.fields['参数名'] = '参数值';
//上传文件
File file = File(); //此处用需要上传的文件替换
//第一个参数对应参数名,第二个参数对应文件地址
var multipartFile = await http.MultipartFile.fromPath('参数名', '文件地址');
//文件添加进请求
request.files.add(multipartFile);
var response = await request.send();
if (response.statusCode == 200) {
var respStr = await response.stream.transform(utf8.decoder).join();
print("upload response is $respStr");
}
参考:https://www.it1352.com/2087171.html