GithubHelp home page GithubHelp logo

Comments (6)

huhx avatar huhx commented on August 15, 2024

在考虑cancel的功能,可以了解一下你这边在上传过程需要取消的场景吗?有简单的代码最好

from flutter_oss_aliyun.

LIYONGBIN123456 avatar LIYONGBIN123456 commented on August 15, 2024

在考虑cancel的功能,可以了解一下你这边在上传过程需要取消的场景吗?有简单的代码最好

是的上传过程中有取消的操作,代码是在项目里面的,耦合的东西比较多,我试试看能不能抽出来

from flutter_oss_aliyun.

huhx avatar huhx commented on August 15, 2024

我写了些测试样例代码:

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.

huhx avatar huhx commented on August 15, 2024

准备在所有的api添加一个可选的参数CancelToken,当调用CancelToken里面的cancel方法,会取消request的请求。

from flutter_oss_aliyun.

LIYONGBIN123456 avatar LIYONGBIN123456 commented on August 15, 2024

应该能满足基本需求了,后面测试一下,如果出现问题,继续给你提issue。非常感谢

from flutter_oss_aliyun.

huhx avatar huhx commented on August 15, 2024

^5.1.4,所有api都添加了可选的参数CancelToken,用于request的cancel。

from flutter_oss_aliyun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.