gpt4 book ai didi

sockets - Dio-Flutter Image Upload返回套接字异常

转载 作者:行者123 更新时间:2023-12-03 11:54:51 56 4
gpt4 key购买 nike

我尝试使用Dio插件支持的formData上传图像。

FormData formData = new FormData.from(
{"profile_image": UploadFileInfo(image, "profile_image.jpg")});
var response = await _dio.post(ApiConfiguration.getUploadImageUrl().toString(),data: formData);

但是它的返回错误。
DioError [DioErrorType.DEFAULT]: SocketException: OS Error: Connection reset by peer, errno = 54, address = 3.122.199.93, port = 62181

任何帮助,将不胜感激。

最佳答案

v3中不建议使用UploadFileInfo和FormData.from。文档需要更清晰和更新。我浪费了一天的大部分时间。

我用dio通过这种方式发布带有其他信息的文件路径:

 Dio dio = new Dio();
FormData formData = new FormData();
formData.add(
"apiKey",
"my_api_key",
);
formData.add(
"file",
"image_path",
);
Response response = await dio.post(
"https://localhost",
data: formData,
onSendProgress: (int sent, int total) {
// do something
},
).catchError((onError) {
throw Exception('something');
});

关于sockets - Dio-Flutter Image Upload返回套接字异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55239198/

56 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com