| Info | Value |
| ------------------------------ | ----------------------------------------------------- |
| Platform Name | flutter |
| Platform Version | Not specific |
| Dio Version | 3.0.0 |
| Android Studio / Xcode Version | Android Studio 3.5 |
| Repro rate | all the time (100%) |
| Repro with our demo prj | demo does not including related content |
| Demo project link | can't provided |
First congratulate with the brand new version of Dio released.
首先恭喜Dio的新版本发布~
In my case, Uint8List image data will be converted to str instead of binary according to PyCharm's log.
在我的业务中,根据PyCharm的日志,Uint8List形式的图片数据被转化成了字符串而不是二进制数据。
As I proceed with the same method, adding a transformer, etc. It just post a string, still.
在我使用了与相关方法后,添加了数据转换等,问题依旧。
Some of my code provided below:
下面提供部分上传实现代码:
static Future updateUserAvatar(Uint8List avatar) async {
FormData formData = FormData.fromMap({
"avatar": MultipartFile.fromBytes(avatar),
});
return NetUtils.post(
API.saveUserInfo,
data: formData,
);
}
static Future post(String url, {data, headers}) async {
Dio _dio = Dio();
return await _dio.post(
url,
data: data,
options: Options(
headers: headers ?? buildAuthHeader(),
)
);
}
Please help me with this when you have spare time, thx a lot.
若您有时间,请帮助我解决这个问题,非常感谢!
FormData所有的内容最终都是以2进制上传的,你说“完整log中显示我传出的是string”,这个是根据什么判断的?如果是根据content-type,那么你可以指定一下MultipartFile的contentType
后端的PyCharm显示我传出的内容是str,正常接收应该为binary。

恰逢国庆,只能节后再继续调试了,国庆快乐!
1、在formdata example中,并没有使用fromBytes构造FormData的示例,还麻烦进一步补充;
2、在使用fromBytes时,根据业务代码转换出来的Uint8List发送一直被接收为str (PyCharm),为MultipartFile指定contentType为MediaType("image", "png")无效;
3、最终将数据存至File后构建上传成功。
仍认为其中存在部分问题。
同样的问题
根据群友做的大量测试,目前已定位问题,fromBytes方法指定filename可解决。请考虑将文档及example完善。此原因由何导致?
根据群友做的大量测试,目前已定位问题,
fromBytes方法指定filename可解决。请考虑将文档及example完善。此原因由何导致?
我都是指定filename的,反正不行
Having same kind of issue in dio, As in our back-end they are accepting only binary data for file, I would like to have option to pass binary in body instead string,
I'm trying to pass byte[] in body but automatically converting into string and the content-type:application/octet-stream which I'm not sure it's doing anything with that, please help or suggest any solution.
Solution:
What I have done is converting bytes into stream and passing in the body
List<int> imageBytes = File(path).readAsBytesSync();
var file = MultipartFile.fromBytes(imageBytes).finalize();
Dio().post('api/', data: file);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.
@wendux Please take a look.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.
Still, it's an issue.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.
Having same kind of issue in dio, As in our back-end they are accepting only binary data for file, I would like to have option to pass binary in body instead string,
I'm trying to pass byte[] in body but automatically converting into string and the content-type:application/octet-stream which I'm not sure it's doing anything with that, please help or suggest any solution.
Solution:
What I have done is converting bytes into stream and passing in the bodyList<int> imageBytes = File(path).readAsBytesSync(); var file = MultipartFile.fromBytes(imageBytes).finalize(); Dio().post('api/', data: file);
Thanks! It works :)
Having same kind of issue in dio, As in our back-end they are accepting only binary data for file, I would like to have option to pass binary in body instead string,
I'm trying to pass byte[] in body but automatically converting into string and the content-type:application/octet-stream which I'm not sure it's doing anything with that, please help or suggest any solution.
Solution:
What I have done is converting bytes into stream and passing in the bodyList<int> imageBytes = File(path).readAsBytesSync(); var file = MultipartFile.fromBytes(imageBytes).finalize(); Dio().post('api/', data: file);Thanks! It works :)
这样怎么指定上传的文件的key呢?
dio在文件上传这里确实有问题,试了很多办法都不行
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.
Eww, another library waiting for abandon...
Most helpful comment
Having same kind of issue in dio, As in our back-end they are accepting only binary data for file, I would like to have option to pass binary in body instead string,
I'm trying to pass byte[] in body but automatically converting into string and the content-type:application/octet-stream which I'm not sure it's doing anything with that, please help or suggest any solution.
Solution:
What I have done is converting bytes into stream and passing in the body