Giter VIP home page Giter VIP logo

react-native-aliyun-oss's Introduction

react-native-aliyun-oss

travis npm

安装

npm install --save react-native-aliyun-oss-cp1

link libaray in your android and IOS project

兼容IPv6-Only网络

OSS移动端SDK为了解决无线网络下域名解析容易遭到劫持的问题,已经引入了HTTPDNS进行域名解析,直接使用IP请求OSS服务端。在IPv6-Only的网络下,可能会遇到兼容性问题。而APP官方近期发布了关于IPv6-only网络环境兼容的APP审核要求,为此,SDK从2.5.0版本开始已经做了兼容性处理。在新版本中,除了-ObjC的设置,还需要引入两个系统库:

libresolv.tbd
SystemConfiguration.framework

使用

import AliyunOSS from 'react-native-aliyun-oss-cp1'

AliyunOSS.enableOSSLog();
    const config = {
      AccessKey: '',  // your accessKeyId
      SecretKey: '', // your accessKeySecret
      SecretToken: '', // your securityToken
    };
    const endPoint = ''; // your endPoint
    // 初始化阿里云组件
    AliyunOSS.initWithKey(config, endPoint);
    // upload config
    const uploadConfig = {
      bucketName: '',  //your bucketName
      sourceFile: '', // local file path
      ossFile: '' // the file path uploaded to oss
    };
    // 上传进度
    const uploadProgress = p => console.log(p.currentSize / p.totalSize);
    // 增加上传事件监听
    AliyunOSS.addEventListener('uploadProgress', uploadProgress);
    // 执行上传
    AliyunOSS.uploadObjectAsync(uploadConfig).then((resp) => {
      // 去除事件监听
      AliyunOSS.removeEventListener('uploadProgress', uploadProgress);
      // 此处可以执行回调
      ... 
    }).catch((err)=>{
      console.log(err);
      // 执行失败回调
      ...
});

...

// download
const downloadConfig = {
      bucketName: '',
      ossFile: '' // the file path on the oss
    };
const downloadProgress = p => console.log(p.currentSize / p.totalSize);
AliyunOSS.addEventListener('downloadProgress', downloadProgress);
await AliyunOSS.downloadObjectAsync(downloadConfig).then(path => {
  console.log(path); // the local file path downloaded from oss
  AliyunOSS.removeEventListener('downloadProgress', downloadProgress);
}).catch((error) => {
  console.error(error);
});

更新日志

2017-02-10 修复组件在ios8/9 上传时可能出现崩溃的问题

感谢

代码来源于原作者@lesonli

因为在使用过程中遇到一些问题,上传图片阿里云会报错 "The OSS Access Key Id you provided does not exist in our records."

初步判断是因为原作者的native层init客户端方式使用的是 OSSPlainTextAKSKPairCredentialProvider, 不传securityToken,导致阿里云鉴权出问题。(个人猜测)

改了ios和安卓底层的代码,把init方式修改成了OSSStsTokenCredentialProvider,上传成功。

原作传送门:https://github.com/lesonli/react-native-aliyun-oss 再次感谢。

react-native-aliyun-oss's People

Contributors

spadegod avatar 431910864 avatar kala888 avatar suetming avatar

Stargazers

 avatar

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.