Comments (6)
在考虑cancel的功能,可以了解一下你这边在上传过程需要取消的场景吗?有简单的代码最好
from flutter_oss_aliyun.
在考虑cancel的功能,可以了解一下你这边在上传过程需要取消的场景吗?有简单的代码最好
是的上传过程中有取消的操作,代码是在项目里面的,耦合的东西比较多,我试试看能不能抽出来
from flutter_oss_aliyun.
我写了些测试样例代码:
final CancelToken cancelToken = CancelToken();
final File file = File("$home/Downloads/idiom.csv");
final String string = file.readAsStringSync();
await Client().putObject(
Uint8List.fromList(utf8.encode(string)),
"cancel_token_test.csv",
option: PutRequestOption(
onSendProgress: (count, total) {
if (kDebugMode) {
print("send: count = $count, and total = $total");
}
if (count > 56) {
cancelToken.cancel("cancel the uploading.");
}
},
),
cancelToken: cancelToken,
).then((response) {
// success
print("upload success = ${response.statusCode}");
}).catchError((err) {
if (CancelToken.isCancel(err)) {
print("error message = ${err.message}");
} else {
// handle other errors
}
});
代码中在上传bytes > 56时,cancel上传。cancelToken.cancel
这个方法会throw DioError.cancel,然后在catchError中,使用if (CancelToken.isCancel(err))判断error是否来自于cancel的,可以对这种特定的error做处理。
不知道这个满不满足你的场景
from flutter_oss_aliyun.
准备在所有的api添加一个可选的参数CancelToken,当调用CancelToken里面的cancel方法,会取消request的请求。
from flutter_oss_aliyun.
应该能满足基本需求了,后面测试一下,如果出现问题,继续给你提issue。非常感谢
from flutter_oss_aliyun.
^5.1.4,所有api都添加了可选的参数CancelToken,用于request的cancel。
from flutter_oss_aliyun.
Related Issues (20)
- NextContinuationToken 出现 HOT 2
- 这个能改改吗 HOT 2
- 请问大家是如何获得token的呢? HOT 2
- 如何处理多个Bucket的情况? HOT 3
- FormatException: Invalid date format HOT 1
- secureToken 怎么本地获取?
- 请求使用帮助,我无法使用ak以访问aliyun oss HOT 1
- 上传相册图片该用putobjectfile还是putobject HOT 9
- 自定义auth的方式可行吗?有没有具体例子可以参考呢? HOT 2
- 文件样式(Style)功能添加 HOT 2
- 判断文件是否存在接口 HOT 2
- 报错Unhandled Exception: type 'String' is not a subtype of type 'Map<String, dynamic>' HOT 11
- Ossutil 可以上传, 使用这个就报错啊 HOT 4
- 403报错 HOT 2
- Error: DioException [connection error]: The connection errored: The XMLHttpRequest onError callback was called. This typically indicates an error on the network layer. This indicates an error which most likely cannot be solved by the library. HOT 2
- The 'aliyun_sls/flutter_sdk' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.
- flutter web在上传视频文件时,页面会冻结无法操作 HOT 3
- 请问这个怎么使用的啊。初始化的时候配置stsUrl就可以了吗? HOT 5
- 为啥上传的图片都被限制93b大小,图片都打不开 HOT 3
- secureToken,客户端可以自己生成吗? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_oss_aliyun.