flutter dio upload image type application/octet-stream to image/jpeg
Irder外贸平台,个人免费入驻 https://www.irder.com
MediaType? mediaType;
if (_fileToUpload.path.endsWith('jpg') ||
_fileToUpload.path.endsWith('jpeg')) {
mediaType = MediaType("image", "jpeg");
} else if (_fileToUpload.path.endsWith('png')) {
mediaType = MediaType("image", "png");
}
if (_fileToUpload.path.isNotEmpty) {
// Create a FormData
String fileName = basename(_fileToUpload.path);
print("File Name : $fileName");
print("File Size : ${_fileToUpload.lengthSync()}");
print("File Type : $mediaType");
_formData = FormData.fromMap({
"product_images": await MultipartFile.fromFile(_fileToUpload.path,
filename: fileName, contentType: mediaType)
});
}
解决方案就是更改contentType参数
评论
登陆评论
没有评论