uploadImgFunc(File image) async {
String path = image.path;
String name = path.substring(path.lastIndexOf("/") +1, path.length);
String suffix = name.substring(name.lastIndexOf(".") +1, name.length);
FormData formData = FormData.fromMap({"uploadFile":await MultipartFile.fromFile(//这里记得加awaitpath, filename: name, contentType:MediaType('image',suffix) ), });
Dio dio =newDio();
var result =await dio.post('接口', data: formData);print(result); }
dio3.0之后就使用MultipartFile不再使用UploadFileInfo。
MediaType这个需要额外引一个头文件,不然会报错
import 'package:http_parser/http_parser.dart';
网友评论