diff --git a/lib/util/net_util.dart b/lib/util/net_util.dart index 0e97a16..bee12f8 100644 --- a/lib/util/net_util.dart +++ b/lib/util/net_util.dart @@ -357,6 +357,28 @@ class NetUtil { return EncodeUtil.generateMd5(path + map.toString()); } + // 七牛云文件上传 + static Future uploadFile(String url, File file, + {String method = 'POST', + Map params, + OnSuccess onSuccess, + OnError onError}) async { + if (params == null) { + params = {}; + } + Dio dio = Dio(BaseOptions( + method: "post", + connectTimeout: 15000, + receiveTimeout: 15000, + contentType: Headers.jsonContentType, + followRedirects: true, + )); + + params['file'] = await MultipartFile.fromFile(file.path); + FormData format = FormData.fromMap(params); + return dio.request(url, data: format, options: Options(method: method)); + } + /// 签名 static String signWithArray(List params) { // 字母升序