使用阿里云oss上传图片遇到的问题

现在上传会报这样的错误 {
It's recommended to set 'refreshSTSToken' and 'refreshSTSTokenInterval' to refresh stsToken、accessKeyId、accessKeySecret automatically when sts token has expired

      PUT http://wc-demo.oss-cn-zhangjiakou.aliyuncs.com/origin_202201212222195141.jpg 403 (Forbidden),

      InvalidAccessKeyIdError: The OSS Access Key Id you provided does not exist in our records

}
第一个是警告,下面两个是报错。
方法:

export function client(OssDto) {
    let OSS = require("ali-oss");
    let client = new OSS({
        region: OssDto.region,
        accessKeyId: OssDto.accessKeyId,
        accessKeySecret: OssDto.accessKeySecret,
        bucket: OssDto.bucket,
        stsToken: OssDto.stsToken
    });
    return client

}
引入:

import { client } from "../../assets/js/oss";

上传成功的方法:

client(this.OssDto).put(file.name, file.raw).then(res=>{
        console.log(res)
      })

 file.name:origin_202201212222195141.jpg,
file.raw:uid: 1645597872915
               lastModified: 1642814126718
                lastModifiedDate: Sat Jan 22 2022 09:15:26 GMT+0800 (中国标准时间) {}
                name: "origin_202201212222195141.jpg"
                size: 24733
                type: "image/jpeg"
                webkitRelativePath: ""

百度了好久实在不知道是哪里的原因,请问是put下传的参数有问题吗?

accessKeyId: "LT"
accessKeySecret: "0SZ"
bucket: "wc-de"
region: "oss-cn"
stsToken: "CAI"

以上是返回来的数据格式

The OSS Access Key Id you provided does not exist in our records

这句话是告诉你,你提供的OSS Access Key Id不存在于阿里云的记录里,所以检查下是不是参数写错了

检查一下你的accesskey,和accesskeysecret是不是配置对了。这个在你的阿里云后台

你当时是不是使用了一个固定的token,他提示你token过期了,而且推荐你使用定期刷新token的方式,判断,如果token过期,则重新获取。

问题解决了,上传的时候不需要stsToken

@weixin_34390105
但是我在pc端的时候加上 stsToken 是可以正常执行的,在app端就不行了。