npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-aliyun-oss-cp1

v1.0.7

Published

upload file to aliyun oss

Downloads

5

Readme

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 再次感谢。