jlcool / aliossflutter

阿里云oss flutter
Apache License 2.0
76 stars 47 forks source link

Compute signature failed! #35

Open gaoyong06 opened 4 years ago

gaoyong06 commented 4 years ago

在应用刚打开的时候,调用初始化

String stsPath = UrlPath.baseUrl + UrlPath.stsToken;
AliOSSFlutter  alioss = AliOSSFlutter();
alioss.init(stsPath, "http://oss-cn-hangzhou.aliyuncs.com");
//监听初始化
alioss.responseFromInit.listen((data){
    if(data) { 
        logger.i("阿里云oss初始化成功");
    }else{
    logger.i("阿里云oss初始化失败");
    }
});

stsPath是后台提供的一个api接口地址, 接口返回值是:

{
    "StatusCode":200,
    "AccessKeyId":"STS.NUYs1PG9rDboZ2t2ixzNp2v6n",
    "AccessKeySecret":"7sZVNpUKeoVKsSLqc3KNpjSJnK2JYUGRfUkH318vYPvq",
    "Expiration":"2020-06-16T04:49:13Z",
    "SecurityToken":"CAISlQJ1q6Ft5B2yfSjIr5bsOIvkquZT86CEWBTF1mktdsFc3bOdjDz2IHpJfXloAOAWtf4+mWhW7vwflqJ4T55IQ1Dza8J148yNdb0SoMyT1fau5Jko1beXewHKeSOZsebWZ+LmNqS/Ht6md1HDkAJq3LL+bk/Mdle5MJqP+/EFA9MMRVv6F3kkYu1bPQx/ssQXGGLMPPK2SH7Qj3HXEVBjt3gb6wZ24r/txdaHuFiMzg+46JdM+9uoeML6P5c9YMwmD43t5oEsKPqdihw3wgNR6aJ7gJZD/Tr6pdyHCzFTmU7cbrOEqoQ/fFQjN/ViRfYe8eKPnPl5q/HVkJ/s1xFOMOdaXiLSXom8x9HeH+ekJkKpo0k4kdKnGoABsC0SQVCTHsxSX94BfTgkz59fRKZbur81anIU9AdqwW+/5ZOpaXgwlmIFMgtOg/DVb2O+ThRQFLag5aGImGX8AhrE7GIpaPeaTvzPbE8S0f5yG/0j5YJToZd4Sne3cY2otPPocru40iOXqj1Yf5j8JPewISZ/+ReqY0nm7t+Ykfw="
}

执行后打印了下面的日志

I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   Global.init.<anonymous closure> (package:qzone_app/common/Global.dart:138:18)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 阿里云oss初始化成功
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   Global.init.<anonymous closure> (package:qzone_app/common/Global.dart:138:18)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 阿里云oss初始化成功
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

从日志上面看,初始化已成功:

然后选择图片上传,我封装了下面方法:

  ///oss上传文件
  ///使用:aliossflutter上传
  ///现在存在的bug: https://github.com/jlcool/aliossflutter/issues/27
  /// context flutter的上下文
  /// uid 上传文件所属的uid(一般是登录用户uid)
  /// bucket 上传到oss 的bucket name
  /// type 上传文件的业务类型
  /// key 上传后文件的路径及文件名(即:oss 里面的key)
  /// file 准备上传的文件
  static Future<OssCallBackData> ossUploadFile2(BuildContext context, int uid, String bucket, String type, String key, File file) {

      String path = file.path;
      String key = OssHelper.buildOssKey(path, uid);
      AliOSSFlutter  alioss = AliOSSFlutter();
      Map<String, dynamic> ossConfig = getOssConfig(key, type, uid);
      logger.i("上传回调参数:$ossConfig");

      //url签名:
      //type=1 签名私有资源
      //type=0 签名公开的访问URL
      alioss.signUrl(bucket, key);

      //监听url签名
      alioss.responseFromSign.listen((data){
        if(data.success) {
          logger.i("url 签名 :${data.url}");
        }else{
          logger.i("url 签名失败");
        }
      });

      //上传
      //callbackHost    
      //发起回调请求时 Host 头的值,只有在设置了 callbackUrl 时才有效。
      //如果没有配置 callbckHost,则会解析 callbackUrl 中的 url 并将解析出的 host 填充到 callbackHost 中。
      //参考文档:https://help.aliyun.com/document_detail/31989.html?spm=a2c4g.11186623.2.30.6c474c07zQ8Q3w
      alioss.upload(bucket, file.path, key,
        callbackUrl: ossConfig['callbackUrl'],
        callbackBodyType: ossConfig['callbackBodyType'],
        callbackBody: ossConfig['callbackBody'],
        callbackVars: ossConfig['callbackVars']);

      //监听上传
      alioss.responseFromUpload.listen((data) {

        logger.i("data.success:${data.success}");
        logger.i("data.key:${data.key}");
        logger.i("data.msg:${data.msg}");
        logger.i("data.servercallback:${data.servercallback}");

        if(data.success) {

            logger.i("上传成功 key: ${data.key} 服务器回调返回值:${data.servercallback}");

        }else{
          logger.i("上传失败");
        }

      });

      alioss.responseFromProgress.listen((data){
        if(data.key==key) {
          logger.i("上传进度:${data.getProgress()} ");
        }
      });
  }

执行后,一直在报错,相关的日志如下:

I/flutter (23991): 相册选择图片 开始执行
I/flutter (23991): 图片实际地址:/storage/emulated/0/sina/weibo/storage/video_download/cover/103778_1034:4505587493568548.jpg
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   _UserIndexPageState._uploadFile (package:qzone_app/pages/user/UserIndexPage.dart:476:12)
I/flutter (23991): │ #1   _UserIndexPageState._getActionSheetList.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:qzone_app/pages/user/UserIndexPage.dart:352:23)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡  _uploadFile 开始执行 
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   OssHelper.ossUploadFile2 (package:qzone_app/helper/OssHelper.dart:74:14)
I/flutter (23991): │ #1   _UserIndexPageState._uploadFile (package:qzone_app/pages/user/UserIndexPage.dart:483:17)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 上传回调参数:{callbackUrl: https://api4.qqhot.com/osscallback/index, callbackBody: {"bucket":${bucket},"object":${object},"etag":${etag},"size":${size},"mimeType":${mimeType},"height":${imageInfo.height},"width":${imageInfo.width},"format":${imageInfo.format},"type":${x:type},"uid":${x:uid}}, callbackBodyType: application/json, callbackVars: {"x:type":"user_mobile_wallpaper", "x:uid":"2262561"}}
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
E/flutter (23991): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'then' was called on null.
E/flutter (23991): Receiver: null
E/flutter (23991): Tried calling: then<Null>(Closure: (OssCallBackData) => Null)
E/flutter (23991): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (23991): #1      _UserIndexPageState._uploadFile (package:qzone_app/pages/user/UserIndexPage.dart:483:95)
E/flutter (23991): #2      _UserIndexPageState._getActionSheetList.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:qzone_app/pages/user/UserIndexPage.dart:352:23)
E/flutter (23991): #3      State.setState (package:flutter/src/widgets/framework.dart:1233:30)
E/flutter (23991): #4      _UserIndexPageState._getActionSheetList.<anonymous closure>.<anonymous closure> (package:qzone_app/pages/user/UserIndexPage.dart:347:21)
E/flutter (23991): #5      _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter (23991): #6      _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (23991): #7      _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
E/flutter (23991): #8      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter (23991): #9      Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter (23991): #10     Future._completeWithValue (dart:async/future_impl.dart:526:5)
E/flutter (23991): #11     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
E/flutter (23991): #12     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:298:13)
E/flutter (23991): #13     PhotoManager._getFileWithId (package:photo_manager/src/manager.dart)
E/flutter (23991): #14     _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter (23991): #15     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (23991): #16     _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
E/flutter (23991): #17     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter (23991): #18     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter (23991): #19     Future._completeWithValue (dart:async/future_impl.dart:526:5)
E/flutter (23991): #20     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
E/flutter (23991): #21     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:298:13)
E/flutter (23991): #22     MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart)
E/flutter (23991): #23     _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter (23991): #24     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (23991): #25     _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
E/flutter (23991): #26     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter (23991): #27     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter (23991): #28     Future._completeWithValue (dart:async/future_impl.dart:526:5)
E/flutter (23991): #29     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
E/flutter (23991): #30     _rootRun (dart:async/zone.dart:1184:13)
E/flutter (23991): #31     _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (23991): #32     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter (23991): #33     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
E/flutter (23991): #34     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter (23991): #35     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
E/flutter (23991): 
W/System.err(23991): java.lang.IllegalStateException: Compute signature failed!
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.sign(OSSUtils.java:475)
W/System.err(23991):    at com.jlcool.aliossflutter.AliossflutterPlugin$1.signContent(AliossflutterPlugin.java:137)
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.signRequest(OSSUtils.java:699)
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:86)
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:44)
W/System.err(23991):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err(23991):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err(23991):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err(23991):    at java.lang.Thread.run(Thread.java:818)
W/System.err(23991): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] java.lang.String.getBytes(java.lang.String)' on a null object reference
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.auth.HmacSHA1Signature.computeSignature(HmacSHA1Signature.java:48)
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.sign(OSSUtils.java:472)
W/System.err(23991):    ... 8 more
I/flutter (23991): estimateMaxScrollOffset:  firstIndex: 0, lastIndex: 2
I/flutter (23991): didFinishLayout:  firstIndex: 0, lastIndex: 2
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   OssHelper.ossUploadFile2.<anonymous closure> (package:qzone_app/helper/OssHelper.dart:84:18)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 url 签名 :http://qzone-pic1.oss-cn-hangzhou.aliyuncs.com/2020/06/16/82bfe28a56a3e8bb4f52b0b4524bc8a2.jpg
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
W/System.err(23991): java.lang.IllegalStateException: Compute signature failed!
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.sign(OSSUtils.java:475)
W/System.err(23991):    at com.jlcool.aliossflutter.AliossflutterPlugin$1.signContent(AliossflutterPlugin.java:137)
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.signRequest(OSSUtils.java:699)
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:86)
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:239)
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:44)
W/System.err(23991):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err(23991):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err(23991):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err(23991):    at java.lang.Thread.run(Thread.java:818)
W/System.err(23991): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] java.lang.String.getBytes(java.lang.String)' on a null object reference
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.auth.HmacSHA1Signature.computeSignature(HmacSHA1Signature.java:48)
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.sign(OSSUtils.java:472)
W/System.err(23991):    ... 9 more
W/System.err(23991): com.alibaba.sdk.android.oss.ClientException: Compute signature failed!
W/System.err(23991): [ErrorMessage]: Compute signature failed!
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:200)
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:239)
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:239)
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:44)
W/System.err(23991):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err(23991):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err(23991):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err(23991):    at java.lang.Thread.run(Thread.java:818)
W/System.err(23991): Caused by: java.lang.IllegalStateException: Compute signature failed!
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.sign(OSSUtils.java:475)
W/System.err(23991):    at com.jlcool.aliossflutter.AliossflutterPlugin$1.signContent(AliossflutterPlugin.java:137)
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.signRequest(OSSUtils.java:699)
W/System.err(23991):    at com.alibaba.sdk.android.oss.network.OSSRequestTask.call(OSSRequestTask.java:86)
W/System.err(23991):    ... 7 more
W/System.err(23991): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] java.lang.String.getBytes(java.lang.String)' on a null object reference
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.auth.HmacSHA1Signature.computeSignature(HmacSHA1Signature.java:48)
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.sign(OSSUtils.java:472)
W/System.err(23991):    ... 10 more
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   OssHelper.ossUploadFile2.<anonymous closure> (package:qzone_app/helper/OssHelper.dart:104:16)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 data.success:false
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   OssHelper.ossUploadFile2.<anonymous closure> (package:qzone_app/helper/OssHelper.dart:105:16)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 data.key:2020/06/16/82bfe28a56a3e8bb4f52b0b4524bc8a2.jpg
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   OssHelper.ossUploadFile2.<anonymous closure> (package:qzone_app/helper/OssHelper.dart:106:16)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 data.msg:Compute signature failed!
I/flutter (23991): │ 💡 [ErrorMessage]: Compute signature failed!
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   OssHelper.ossUploadFile2.<anonymous closure> (package:qzone_app/helper/OssHelper.dart:107:16)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 data.servercallback:null
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   OssHelper.ossUploadFile2.<anonymous closure> (package:qzone_app/helper/OssHelper.dart:114:18)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 上传失败
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

请问我是哪里搞错了?

gaoyong06 commented 4 years ago

上面有个可疑的地方,就是“阿里云oss初始化成功”被打印了2次,我又增加一日志看了一下,我使用的没错,是回调里面调用了2次 相关的代码和日志,如下:

logger.i("阿里云oss初始化开始");
String stsPath = UrlPath.baseUrl + UrlPath.stsToken;
AliOSSFlutter  alioss = AliOSSFlutter();
alioss.init(stsPath, "http://oss-cn-hangzhou.aliyuncs.com");
//监听初始化
alioss.responseFromInit.listen((data){
  if(data) { 
      logger.i("阿里云oss初始化成功");
  }else{
    logger.i("阿里云oss初始化失败");
  }
});

打印的日志:

I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   Global.init (package:qzone_app/common/Global.dart:132:12)
I/flutter (23991): │ #1   <asynchronous suspension>
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 阿里云oss初始化开始
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
W/System.err(23991): android.os.NetworkOnMainThreadException
W/System.err(23991):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
W/System.err(23991):    at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
W/System.err(23991):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
W/System.err(23991):    at java.net.InetAddress.getByName(InetAddress.java:305)
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.isValidateIP(OSSUtils.java:795)
W/System.err(23991):    at com.alibaba.sdk.android.oss.OSSImpl.<init>(OSSImpl.java:133)
W/System.err(23991):    at com.alibaba.sdk.android.oss.OSSClient.<init>(OSSClient.java:116)
W/System.err(23991):    at com.jlcool.aliossflutter.AliossflutterPlugin.init(AliossflutterPlugin.java:246)
W/System.err(23991):    at com.jlcool.aliossflutter.AliossflutterPlugin.onMethodCall(AliossflutterPlugin.java:93)
W/System.err(23991):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
W/System.err(23991):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
W/System.err(23991):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
W/System.err(23991):    at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(23991):    at android.os.MessageQueue.next(MessageQueue.java:143)
W/System.err(23991):    at android.os.Looper.loop(Looper.java:122)
W/System.err(23991):    at android.app.ActivityThread.main(ActivityThread.java:5305)
W/System.err(23991):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err(23991):    at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err(23991):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:922)
W/System.err(23991):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:717)
W/System.err(23991): android.os.NetworkOnMainThreadException
W/System.err(23991):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
W/System.err(23991):    at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
W/System.err(23991):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
W/System.err(23991):    at java.net.InetAddress.getByName(InetAddress.java:305)
W/System.err(23991):    at com.alibaba.sdk.android.oss.common.utils.OSSUtils.isValidateIP(OSSUtils.java:795)
W/System.err(23991):    at com.alibaba.sdk.android.oss.OSSImpl.<init>(OSSImpl.java:133)
W/System.err(23991):    at com.alibaba.sdk.android.oss.OSSClient.<init>(OSSClient.java:116)
W/System.err(23991):    at com.alibaba.sdk.android.oss.OSSClient.<init>(OSSClient.java:104)
W/System.err(23991):    at com.jlcool.aliossflutter.AliossflutterPlugin.secretInit(AliossflutterPlugin.java:140)
W/System.err(23991):    at com.jlcool.aliossflutter.AliossflutterPlugin.onMethodCall(AliossflutterPlugin.java:95)
W/System.err(23991):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
W/System.err(23991):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
W/System.err(23991):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
W/System.err(23991):    at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(23991):    at android.os.MessageQueue.next(MessageQueue.java:143)
W/System.err(23991):    at android.os.Looper.loop(Looper.java:122)
W/System.err(23991):    at android.app.ActivityThread.main(ActivityThread.java:5305)
W/System.err(23991):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err(23991):    at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err(23991):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:922)
W/System.err(23991):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:717)
I/flutter (23991): Global 开始完成
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   Global.init.<anonymous closure> (package:qzone_app/common/Global.dart:139:18)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 阿里云oss初始化成功
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23991): │ #0   Global.init.<anonymous closure> (package:qzone_app/common/Global.dart:139:18)
I/flutter (23991): │ #1   _rootRunUnary (dart:async/zone.dart:1192:38)
I/flutter (23991): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23991): │ 💡 阿里云oss初始化成功
I/flutter (23991): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
gaoyong06 commented 4 years ago

今天下午又测试一遍,依然还是不行,真不知道是哪里不对 总是报 Compute signature failed!

就一个stsPath https://api4.qqhot.com/sts/token

而且我们线上也一直在用,怎么会错呢?真是奇怪

jlcool commented 4 years ago

alioss.responseFromInit.listen放到initState里,注意sts返回格式,你们自己用的格式可能和需要的不一致

jeryfer commented 4 years ago

我也同样 iOS上可以 Android不可以

baisunwu commented 3 years ago

我也一样 iOS上可以, Android不可以,报Compute signature failed错误,请问这个怎么解决

lazyid commented 3 years ago

同问 安卓里 Compute signature failed