Skip to content

Commit 329a2c8

Browse files
authored
add mimetype (#78)
* add mimetype * update version * fix lint
1 parent a28f46a commit 329a2c8

File tree

11 files changed

+46
-10
lines changed

11 files changed

+46
-10
lines changed

base/lib/src/storage/methods/put/by_part/complete_parts_task.dart

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class CompletePartsTask extends RequestTask<PutResponse> {
66
final String uploadId;
77
final List<Part> parts;
88
final String? key;
9+
final String? mimeType;
910

1011
late final UpTokenInfo _tokenInfo;
1112

@@ -17,6 +18,7 @@ class CompletePartsTask extends RequestTask<PutResponse> {
1718
required this.uploadId,
1819
required this.parts,
1920
this.key,
21+
this.mimeType,
2022
this.customVars,
2123
PutController? controller,
2224
}) : super(controller: controller);
@@ -50,6 +52,10 @@ class CompletePartsTask extends RequestTask<PutResponse> {
5052
data['customVars'] = customVars;
5153
}
5254

55+
if (mimeType != null) {
56+
data['mimeType'] = mimeType;
57+
}
58+
5359
final response = await client.post<Map<String, dynamic>>(
5460
paramUrl,
5561
data: data,

base/lib/src/storage/methods/put/by_part/put_parts_task.dart

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class PutByPartTask extends RequestTask<PutResponse> {
169169
uploadId: uploadId,
170170
parts: parts,
171171
key: resource.name,
172+
mimeType: options.mimeType,
172173
customVars: options.customVars,
173174
controller: controller,
174175
);

base/lib/src/storage/methods/put/put_options.dart

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ class PutOptions {
66
/// 如果不传则后端自动生成
77
final String? key;
88

9+
/// mimeType
10+
///
11+
/// 资源的 MIME 类型,如 image/jpeg
12+
final String? mimeType;
13+
914
/// 强制使用单文件上传,不使用分片,默认值 false
1015
///
1116
/// 如果使用 putStream, 这个值会被忽略
@@ -25,6 +30,7 @@ class PutOptions {
2530

2631
const PutOptions({
2732
this.key,
33+
this.mimeType,
2834
this.forceBySingle = false,
2935
this.partSize = 4,
3036
this.maxPartsRequestNumber = 5,

base/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: qiniu_sdk_base
2-
version: 0.5.1
2+
version: 0.5.2
33
homepage: https://github.com/qiniu/dart-sdk
44
description: The sdk basic of Qiniu products
55

base/test/auth/auth_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void main() {
8383
deadline: 0,
8484
),
8585
'iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV:QtVzBdciokbNk10yD9R11yI1DYU=:eyJzY29wZSI6InRlc3RCdWNrZXQiLCJkZWFkbGluZSI6MH0=',
86-
)
86+
),
8787
];
8888

8989
for (final testData in testDataTable) {

base/test/config.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final env = DotEnv(includePlatformEnvironment: true)..load();
1212
final isSensitiveDataDefined = env.isEveryDefined([
1313
'QINIU_DART_SDK_ACCESS_KEY',
1414
'QINIU_DART_SDK_SECRET_KEY',
15-
'QINIU_DART_SDK_TOKEN_SCOPE'
15+
'QINIU_DART_SDK_TOKEN_SCOPE',
1616
]);
1717

1818
void configEnv() {

base/test/put/helpers.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class PutControllerBuilder {
4848
targetStatusList ??= [
4949
StorageStatus.Init,
5050
StorageStatus.Request,
51-
StorageStatus.Success
51+
StorageStatus.Success,
5252
];
5353
targetProgressList ??= [0.001, 0.99, 1];
5454
expect(statusList, equals(targetStatusList));

base/test/put/put_by_parts/put_bytes_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void main() {
205205
targetStatusList: [
206206
StorageStatus.Init,
207207
StorageStatus.Request,
208-
StorageStatus.Cancel
208+
StorageStatus.Cancel,
209209
],
210210
targetProgressList: [
211211
0.001,

base/test/put/put_by_parts/put_file_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void main() {
165165
targetStatusList: [
166166
StorageStatus.Init,
167167
StorageStatus.Request,
168-
StorageStatus.Cancel
168+
StorageStatus.Cancel,
169169
],
170170
targetProgressList: [
171171
0.001,

base/test/retry_test.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void main() {
5050
StorageStatus.Request,
5151
StorageStatus.Retry,
5252
StorageStatus.Request,
53-
StorageStatus.Error
53+
StorageStatus.Error,
5454
]);
5555
},
5656
skip: !isSensitiveDataDefined,
@@ -127,7 +127,7 @@ void main() {
127127
StorageStatus.Retry,
128128
// 重试后会重新发请求
129129
StorageStatus.Request,
130-
StorageStatus.Success
130+
StorageStatus.Success,
131131
]);
132132
expect(response.key, 'test_for_put.txt');
133133
},
@@ -190,7 +190,7 @@ void main() {
190190
StorageStatus.Request,
191191
StorageStatus.Retry,
192192
StorageStatus.Request,
193-
StorageStatus.Success
193+
StorageStatus.Success,
194194
]),
195195
);
196196
expect(statusList[0], StorageStatus.Init);

flutter/example/lib/main.dart

+24-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class BaseState extends DisposableState<Base> {
3838
// 用户输入的文件名
3939
String? key;
4040

41+
// 用户输入的 mimeType
42+
String? mimeType;
43+
4144
// 用户输入的 partSize
4245
int partSize = 4;
4346

@@ -119,6 +122,7 @@ class BaseState extends DisposableState<Base> {
119122

120123
final putOptions = PutOptions(
121124
key: key,
125+
mimeType: mimeType,
122126
partSize: partSize,
123127
controller: putController,
124128
);
@@ -180,7 +184,7 @@ class BaseState extends DisposableState<Base> {
180184
}
181185

182186
void onSelectedFile(PlatformFile file) {
183-
printToConsole('选中文件: ${file.path}');
187+
printToConsole('选中文件: path: ${file.path}, filename: ${file.name}, size: ${file.size}');
184188
// ignore: unnecessary_null_comparison
185189
if (file.size != null) {
186190
// 一般在非 web 平台上可以直接读取 size 属性
@@ -230,6 +234,18 @@ class BaseState extends DisposableState<Base> {
230234
this.key = key;
231235
}
232236

237+
238+
void onMimeTypeChange(String mimeType) {
239+
if (mimeType == '') {
240+
printToConsole('清除 mimeType');
241+
this.mimeType = null;
242+
return;
243+
}
244+
245+
printToConsole('设置 mimeType: $mimeType');
246+
this.mimeType = mimeType;
247+
}
248+
233249
Widget get cancelButton {
234250
if (statusValue == StorageStatus.Request) {
235251
return Padding(
@@ -257,6 +273,13 @@ class BaseState extends DisposableState<Base> {
257273
label: '请输入 Key(可选)回车确认',
258274
),
259275
),
276+
Padding(
277+
padding: const EdgeInsets.all(8.0),
278+
child: StringInput(
279+
onMimeTypeChange,
280+
label: '请输入 MimeType(可选)回车确认',
281+
),
282+
),
260283
Padding(
261284
padding: const EdgeInsets.all(8.0),
262285
child: StringInput(

0 commit comments

Comments
 (0)