fix:优化图片上传组件,解决png图片报错问题
This commit is contained in:
@@ -37,8 +37,15 @@ class UploadOss {
|
||||
required String ossHost,
|
||||
bool? isShowLoading,
|
||||
}) async {
|
||||
final String normalizedFileType =
|
||||
fileType.toLowerCase() == 'jpeg' ? 'jpg' : fileType.toLowerCase();
|
||||
final bool isVideo = normalizedFileType == 'mp4';
|
||||
final String? imageContentType = isVideo
|
||||
? null
|
||||
: (normalizedFileType == 'jpg' ? 'jpeg' : normalizedFileType);
|
||||
// 生成oss的路径和文件名我这里目前设置的是moment/20201229/test.mp4
|
||||
String pathName = "$rootDir/${getDate()}/app-${getRandom(12)}.$fileType";
|
||||
String pathName =
|
||||
"$rootDir/${getDate()}/app-${getRandom(12)}.$normalizedFileType";
|
||||
|
||||
// 请求参数的form对象
|
||||
FormData formdata = FormData.fromMap({
|
||||
@@ -51,8 +58,8 @@ class UploadOss {
|
||||
'success_action_status': '200',
|
||||
'file': MultipartFile.fromFileSync(
|
||||
path,
|
||||
contentType: fileType == 'mp4' ? null : DioMediaType("image", "jpg"),
|
||||
filename: "${getRandom(12)}.$fileType",
|
||||
contentType: isVideo ? null : DioMediaType("image", imageContentType!),
|
||||
filename: "${getRandom(12)}.$normalizedFileType",
|
||||
),
|
||||
});
|
||||
if (isShowLoading == true) {
|
||||
@@ -71,13 +78,19 @@ class UploadOss {
|
||||
ossHost,
|
||||
data: formdata,
|
||||
options: Options(
|
||||
contentType: "multipart/form-data;image/jpg",
|
||||
headers: {'Content-Type': 'multipart/form-data;image/jpg'},
|
||||
contentType: isVideo
|
||||
? "multipart/form-data"
|
||||
: "multipart/form-data;image/$imageContentType",
|
||||
headers: {
|
||||
'Content-Type': isVideo
|
||||
? "multipart/form-data"
|
||||
: "multipart/form-data;image/$imageContentType",
|
||||
},
|
||||
),
|
||||
);
|
||||
print("response ===== $response");
|
||||
EasyLoading.dismiss();
|
||||
if(fileType == 'jpg'){
|
||||
if (!isVideo && path.contains('compressed_images_')) {
|
||||
/// 删除临时文件
|
||||
File(path).deleteSync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user