Skip to content

使用的时候会报 TypeError: null is not an object #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
eugle opened this issue Feb 19, 2022 · 3 comments
Open

使用的时候会报 TypeError: null is not an object #9

eugle opened this issue Feb 19, 2022 · 3 comments

Comments

@eugle
Copy link

eugle commented Feb 19, 2022

在taro.js 框架中使用,模板是react native
调用任何api,都会报

TypeError: null is not an object (evaluating 'AliOss.enableDevMode')

比如这样

//文件上传
  function upload() {
    console.log("准备上传")

    //open log
    console.log(AliyunOSS);
    if (AliyunOSS) {
      AliyunOSS.enableDevMode() //报错

      // defalut configraiton
      const configuration = {
        maxRetryCount: 3,
        timeoutIntervalForRequest: 30,
        timeoutIntervalForResource: 24 * 60 * 60
      };

      const key = '1'
      const secret = '2'
      const endpoint = "https://oss-cn-shenzhen.aliyuncs.com"
      AliyunOSS.initWithPlainTextAccessKey(key, secret, endpoint, configuration);
      AliyunOSS.asyncUpload('jimuku', 'app', album[0]).then(res => {
        console.log(res);
      }).catch(err => {
        console.log(err);
      })
    }

  }
@eugle
Copy link
Author

eugle commented Feb 19, 2022

是不是方法不对,有没有示例demo,谢谢

@eugle
Copy link
Author

eugle commented Feb 19, 2022

源码中找到的示范

export default function App() {
  const [result, setResult] = React.useState<number | undefined>();

  React.useEffect(() => {
    // AliyunOSS.initWithSecurityToken();
    // AliyunOSS.asyncUpload();
  }, []);

然后这样写

export default function Publish() {

  useEffect(() => {
    const configuration = {
      maxRetryCount: 3,
      timeoutIntervalForRequest: 30,
      timeoutIntervalForResource: 24 * 60 * 60
    };

    const key = ''
    const secret = ''
    const endpoint = "https://oss-cn-shenzhen.aliyuncs.com"
    AliyunOSS.initWithSecurityToken(key, secret, endpoint, configuration);
  }, [])

错误如下:

 ERROR  TypeError: null is not an object (evaluating 'AliOss.initWithSecurityToken')

@emclab
Copy link

emclab commented Mar 15, 2022

keysecret是阿里提供的,不能为空。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants