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

lbd-oss-sdk

v1.0.4

Published

development utils for oss

Downloads

12

Readme

##阿里云OSS前端直传SDK

包下载

npm下载
npm install lbd-oss-sdk -S

淘宝镜像下载
cnpm install lbd-oss-sdk -S

工程化使用ES6/commonjs模块

ES:
import OSS from 'lbd-oss-sdk'

CommonJs: 
const OSS = require('lbd-oss-sdk').default

script引入使用

/node_modules/lbd-oss-sdk/dist/bundle/index.js 为源文件提取自用

###构造器参数

{
  // { boolean } 是否使用服务端签名模式 
  isServerSignature,
  // { string } 加密后的policy信息
  policyBase64,
  // { string } oss的accessKeyId
  accessKeyId,
  // { string } oss的accessKey
  accessKey,
  // { string } oss的bucket
  host,
  // { string } 存放的bucket目录 不能以/开头结尾
  targetDir,
  // { string } 签名串
  signature,
  // { object } policy信息
  policyText = {
    //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了
    "expiration": "2200-01-01T12:00:00.000Z", 
     "conditions": [
        // 设置上传文件的大小限制
        ["content-length-range", 0, 1048576000] 
     ]
  },
}

更多policyText的配置请查阅阿里云OSS帮助文档

前端签名使用(前端签名不推荐使用在浏览器环境下,OSS密钥写在前端容易泄露, 推荐微信小程序使用)

const oss = new OSS({
  accessKeyId: 'LTA***********',
  accessKey: 'dt4g9*****************',
  host: 'https://*****************'
});

后端签名使用(推荐使用在浏览器环境下,后端代签名可以有效保护密钥安全)

const oss = new OSS({
  //开启后端签名模式
  isServerSignature: true,
  //后端提供
  policyBase64: '***************',
  //后端提供
  signature: '***************',
  accessKeyId: 'LTA***********'
  host: 'https://*****************'
});

文件上传

@params file { File } 文件实体(文件对象/小程序临时地址)
@params filename { string } 文件名(带后缀名) 文件名尽量使用UUID/时间戳等不会重名的方式命名,以免覆盖OSS的同名资源
@params targetDir { string } 存放目录(不能以/开头结尾)
oss.upload(file, filename, targetDir)

使用案例(小程序选择照片上传)
let responseURL; 
wx.chooseImage({
  count: 1,
  success: (res) => {
    const file = res.tempFilePaths[0];
    const filename = new Date().getTime() + '.png';
    const targetDir = 'mini/images'
    oss.upload(file, filename, targetDir).then(response => {
      responseURL = response.objectURL || '';
    })
  }
});

使用案例(web选择照片上传)
let responseURL; 
function handleFileChange(ev) {
  const file = ev.target.files[0];
  const filename = new Date().getTime() + '.png';
  const targetDir = 'web/images'
  oss.upload(file, filename, targetDir).then(response => {
    responseURL = response.objectURL;
  });
  ev.target.value = null;
}