我必须在上传 multipartData 的服务器上打电话,但我遇到了这个问题

问题描述

这是我的代码,但我收到此错误

[错误Flutter/lib/ui/ui_dart_state.cc(186)] 未处理的异常: 内容大小超过指定的 contentLength。已写入 17282 字节 预期为 398。

 uploadFile(File imageFile,String id,LoginResponseModel responseModel) async {
 var stream = new http.ByteStream(DelegatingStream.typed(imageFile.openRead()));

 var length = await imageFile.length();

 var uri = Uri.parse(BASE_URL+"/jobs/"+id+"/signatures/");

 Map<String,String> headers = { "Accept": "application/json","content-type": "application/json","Authorization": "Bearer " + responseModel.access};

 var request = new http.MultipartRequest("POST",uri);

 request.headers.addAll(headers);

 request.fields['name'] = 'test';

 var multipartfile = new http.multipartfile('signature',stream,length,filename: basename(imageFile.path));

 request.files.add(multipartfile);


 var response = await request.send();

 print(response.statusCode);

 response.stream.transform(utf8.decoder).listen((value) {
 });

   }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)