File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ import 'dart:convert' ;
2+ import 'dart:io' ;
3+
4+ import 'package:crypto/crypto.dart' ;
5+ import 'package:dio/dio.dart' ;
6+
7+ class UpyunApi {
8+ static const BASE_URL = 'http://v0.api.upyun.com' ;
9+
10+ static const String operatorKey = 'operatorKey' ;
11+ static const String passwordKey = 'passwordKey' ;
12+ }
13+
14+ class UpyunInterceptor extends InterceptorsWrapper {
15+
16+ @override
17+ Future onRequest (RequestOptions options) async {
18+ if (options.path.contains (UpyunApi .BASE_URL )) {
19+ /// 请求方式,如:GET、POST、PUT、HEAD 等
20+ String method = options.method.toLowerCase ();
21+ String path = options.uri.path;
22+ String date = HttpDate .format (DateTime .now ());
23+ String pwdMd5 = '${md5 .convert (options .extra [UpyunApi .passwordKey ])}' ;
24+ String operator = options.extra[UpyunApi .operatorKey];
25+
26+ /// 签名构造
27+ var hmacsha1 = Hmac (sha1, utf8.encode (pwdMd5));
28+ var auth = hmacsha1.convert (utf8.encode ('$method &$path &$date ' ));
29+ String realAuth = base64.encode (auth.bytes);
30+ /// Add Common Header
31+ options.headers.addAll ({
32+ 'Date' : date,
33+ 'Authorization' : 'UPYUN $operator :$realAuth ' ,
34+ });
35+ }
36+ return options;
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ import 'package:flutter_picgo/model/uploaded.dart' ;
2+ import 'dart:io' ;
3+
4+ import 'package:flutter_picgo/utils/strategy/image_upload_strategy.dart' ;
5+
6+ class UpyunImageUpload implements ImageUploadStrategy {
7+ @override
8+ Future <Uploaded > delete (Uploaded uploaded) {
9+ // TODO: implement delete
10+ throw UnimplementedError ();
11+ }
12+
13+ @override
14+ Future <Uploaded > upload (File file, String renameImage) {
15+ // TODO: implement upload
16+ throw UnimplementedError ();
17+ }
18+
19+ }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import 'package:flutter_picgo/utils/strategy/impl/niupic_image_upload.dart';
88import 'package:flutter_picgo/utils/strategy/impl/qiniu_image_upload.dart' ;
99import 'package:flutter_picgo/utils/strategy/impl/smms_image_upload.dart' ;
1010import 'package:flutter_picgo/utils/strategy/impl/tcyun_image_upload.dart' ;
11+ import 'package:flutter_picgo/utils/strategy/impl/upyun_image_upload.dart' ;
1112import 'package:flutter_picgo/utils/strings.dart' ;
1213
1314class UploadStrategyFactory {
@@ -43,6 +44,9 @@ class UploadStrategyFactory {
4344 } else if (type == PBTypeKeys .lsky) {
4445 /// 兰空
4546 cache[type] = new LskyImageUpload ();
47+ } else if (type == PBTypeKeys .upyun) {
48+ /// 又拍云
49+ cache[type] = new UpyunImageUpload ();
4650 }
4751 }
4852 return cache[type];
You can’t perform that action at this time.
0 commit comments