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 🙏

© 2026 – Pkg Stats / Ryan Hefner

uni-cos-sts-upload

v1.0.2

Published

在 uni-app 开发的 app 中,解决实现 app 直传 cos 没有现成 SDK 问题。非 uni-app 做 app 项目,建议优先考虑腾讯云官方SDK,本SDK仅提供 postObject 能力,没有实现全部 cos 能力。

Readme

在 uni-app 开发的 app 中,解决实现 app 直传 cos 没有现成 SDK 问题。非 uni-app 做 app 项目,建议优先考虑腾讯云官方SDK,本SDK仅提供 postObject 能力,没有实现全部 cos 能力。

如何使用

  1. 安装sdk npm install uni-cos-sts-uploadyarn add uni-cos-sts-upload
  2. 引用示例,并 new 一个新的实例(假设是 cos),配置好默认 getAuthorization 函数
  3. 在业务代码中,使用 cos.putObject(文件路径,对象路径) 的方式来实现上传

参考业务代码

工具类封装

// src/utils/cos.js
import { UniCosStsUpload } from "uni-cos-sts-upload";

export default new UniCosStsUpload({
    async getAuthorization() {
        return new Promise((resolve, reject) => {
            uni.request({
                url: "https://localhost/xxx", // 这里是你们后端提供的sts临时秘钥获取地址
                success(res) {
                    // 在这里了将接口返回的临时秘钥信息返回给SDK
                    // sessionToken: 临时密钥安全令牌(必须)
                    // tmpSecretId: 临时密钥ID(必须)
                    // tmpSecretKey: 临时密钥KEY(必须)
                    // bucket: 存储桶名称(非必须,可以APP端写死定制,根据自己业务决定)
                    // region: 存储桶地域(非必须,可以APP端写死定制,根据自己业务决定)
                    // 大部分情况下,一个app不用关联多个cos服务,所以理论是 bucket 和 region 可以 app 端写死,没有风险
                    // 但也有一部分业务确实有一个app关联多个cos服务支持,或者后端想要灵活一点,就可以从接口返回的信息中获取
                    resolve({
                        sessionToken: res.data.credentials.sessionToken,
                        tmpSecretId: res.data.credentials.tmpSecretId,
                        tmpSecretKey: res.data.credentials.tmpSecretKey,
                        bucket: res.data.bucket,
                        region: res.data.region,
                    });
                },
            });
        });
    }
});

业务代码示例

import cos from "../utils/cos.js";

function pickerImage() {
    uni.chooseImage({
        count: 1,
        success: async ({ tempFilePaths }) => {
            for (let tempFilePath of tempFilePath) {
                let response = await cos.putObject(tempFilePath, "xxx/xxx.png");
                console.log("文件信息", response);
            }
        }
    })
}

后端代码参考

本人不是后端,但不表示不会写,这里提供一个简单的参考,仅供参考,具体实现方式根据自己业务决定。

php

composer.json

{
  "require": {
    "qcloud_sts/qcloud-sts-sdk": "3.0.*"
  }
}

.env

#  腾讯云对象存储临时上传秘钥相关
OSS_SECRET_ID=xxx
OSS_SECRET_KEY=xxx
OSS_BUCKET=xxx
OSS_REGION=xxx

Controller

<?php

use QCloud\COSSTS\Sts;

class CosController
{
    public function getOSSTempUploadCredentials(): Response
    {
        try {
            $config = [
                "secretId" => getenv("OSS_SECRET_ID"),
                "secretKey" => getenv("OSS_SECRET_KEY"),
                "durationSeconds" => 3600,
                "bucket" => getenv("OSS_BUCKET"),
                "region" => getenv("OSS_REGION"),
                "allowPrefix" => ["uploads/*"],
                "allowActions" => [
                    "name/cos:PostObject"
                ]
            ];

            $sts = new Sts();
            $tempKeys = $sts->getTempKeys($config);
            $resTemp = array_merge(
                $tempKeys,
                [
                    'startTime' => time(),
                    'bucket' => $config['bucket'],
                    'region' => $config['region']
                ]
            );

            return $this->jsonResponse->success($resTemp);
        } catch (\Exception $e) {
            return $this->jsonResponse->error($e->getMessage());
        }
    }
}