From ecb9f6e5ad7234ae33f8ffac1c26e39cd921ed70 Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Thu, 17 Sep 2020 11:22:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=83=E7=89=9B=E4=BA=91?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/util/net_util.dart | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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) { // 字母升序