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

cos-xml-react-native-fix-upload

v1.0.2

Published

Tencent COS XML SDK for React Native

Downloads

3

Readme

COS XML React Native SDK

安装 SDK

npm install cos-xml-react-native

如果你使用 yarn

yarn add cos-xml-react-native

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

cd ios
pod install

开始使用

1. 导入 SDK

import CosXmlReactNative from 'cos-xml-react-native';

2. 初始化服务

使用临时密钥初始化

// 使用临时密钥初始化
CosXmlReactNative.initWithSessionCredentialCallback({
  region: region
}, async () => {
  // 请求临时密钥
  const response = await fetch(STS_URL);
  const responseJson = await response.json();
  const credentials = responseJson.credentials;
  const expiredTime = responseJson.expiredTime;
  const sessionCredentials = {
    tmpSecretId: credentials.tmpSecretId,
    tmpSecretKey: credentials.tmpSecretKey,
    expiredTime: expiredTime,
    sessionToken: credentials.sessionToken
  };
  console.log(sessionCredentials);
  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)
})

示例

完整的例子请参考 example 示例工程。