我使用Dio框架在我的颤振应用程序中将图像上传到服务器。迪奥版本 3.0.9。发帖方式。添加了 4 个标题创建了带有图像和其他字段的表单数据。
我分析了更多的方法。就像将 Dio 降级到2.3.1一样,使用UploadFileInfo方法。不成功。然后使用multipartfileupload。最后是这个。
Future<bool> createStoreWithDio() async {
Map<String, String> headers = {
"Accept": "application/json",
"authorization": tokenString,
"authtype": "admin",
"Content-Type": "multipart/form-data"
};
try {
FormData formData = new FormData.fromMap({
"logo": await http.MultipartFile.fromPath("logo", imageFile.path,
contentType: new MediaType('image', 'png')),
"name": " Bala ios",
"description": "_description",
"website": "www.website.com",
"password": "Test password",
"user_name": "Test userInformationName",
"mobile": "9988776655",
"email": "test@techit.io",
});
print(formData.fields);
Response response = await dio
.post(
"API",
data: formData,
options: Options(
headers: headers,
),
)
.then((value) {
print(value.toString());
});
print(response.toString());
} catch (error) {
print(error);
}
}
imageFile是我从相机/图库中捕获的文件。
我收到500 个异常。任何帮助都会有所帮助