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

@wu_rong_tai/react-native-cos-xml

v1.0.4

Published

Tencent COS XML SDK for React Native

Downloads

11

Readme

腾讯云对象存储 React Native SDK

Fork from [cos-xml-react-native]

(腾讯云COS文档,自行查看)[https://cloud.tencent.com/document/product/436/12159]

fork 说明

  1. 部分bug修复
  2. 更新安卓SDK版本

安装 SDK

yarn add @wu_rong_tai/react-native-cos-xml

如果没有自动执行 pod 安装,请执行:

cd ios
pod install

开始使用

1. 导入 SDK

import CosXmlReactNative from '@wu_rong_tai/react-native-cos-xml';

2. 初始化服务

使用临时密钥初始化

CosXmlReactNative.initWithSessionCredentialCallback({
    region: region
}, async () => {
  
    // 在此处获取后端 credentials 凭证信息
    const response = await fetch(STS_URL);
    const responseJson = await response.json();
    const credentials = responseJson.credentials;

    const sessionCredentials = {
        tmpSecretId: credentials.tmpSecretId,
        tmpSecretKey: credentials.tmpSecretKey,
        sessionToken: credentials.sessionToken,
        expiredTime: credentials.expiredTime,
        beginTime: credentials.startTime
    };

    return sessionCredentials;
});

使用永久密钥进行本地调试

const SECRET_ID: string = 'Your Secret ID'  // 腾讯云永久密钥 SecretID
const SECRET_KEY: string = 'Your Secret Key'  // 腾讯云永久密钥 SecretKey
// 使用永久密钥进行本地调试
CosXmlReactNative.initWithPlainSecret({
  region: region
}, {
  secretId: SECRET_ID,
  secretKey: SECRET_KEY
})

访问 COS 服务

上传文件

const uploadRequest = {
  bucket: bucket,
  object: objectKey,
  // 文件本地 Uri 或者 路径
  fileUri: 'file://xxx'
}

// 上传 与 暂停后续传对象
// 注意如果是续传,请务必跟初始上传使用同一个 uploadRequest 对象 
CosXmlReactNative.upload(uploadRequest, 
  (processedBytes: number, targetBytes: number) => {
    // 回调进度
    console.log('put Progress callback : ', processedBytes, targetBytes)
    setProgress(processedBytes / targetBytes)
}).then((info) => {
  // info 包含上传结果
  console.log(info)
}).catch((e) => {
  console.log(e)
})

暂停上传请调用:

CosXmlReactNative.pause(uploadRequest)

下载文件

// 下载对象
CosXmlReactNative.download({
  bucket: bucket,
  object: objectKey
}, (processedBytes: number, targetBytes: number) => {
  // 回调进度
  console.log('get Progress callback : ', processedBytes, targetBytes)
  setProgress(processedBytes / targetBytes)
}).then((filePath) => {
  // filePath 是保存到本地的路径
  setSource({uri: "file://" + filePath})
}).catch((e) => {
  console.log(e)
})