@unservice/oss-helper
v1.0.1
Published
![NPM Version](https://img.shields.io/npm/v/@unservice/oss-helper)
Downloads
3
Readme
OSS Helper
安装
npm i @unservice/oss-helper
导入模块
使用 CommonJS Modules
const { OSSUploadHelper } = require('@unservice/oss-helper')
使用 ES Modules
import { OSSUploadHelper } from '@unservice/oss-helper'
使用签名上传文件
const ossUploadHelper = new OSSUploadHelper({
accessKeyId: process.env.ACCESS_KEY_ID,
accessKeySecret: process.env.ACCESS_KEY_SECRET,
bucket: process.env.BUCKET,
endpoint: process.env.ENDPOINT,
cdnDomain: process.env.CDN_DOMAIN,
})
ossUploadHelper.createUploadParams({
keyPrefix: 'path/example',
contentTypes: ['image/webp', 'image/png'],
timeout: 1,
})
对受保护文件进行签名获取临时链接
import { OSSDownloadHelper } from '@unservice/oss-helper'
const ossDownloadHelper = new OSSDownloadHelper({
accessKeyId: process.env.ACCESS_KEY_ID,
accessKeySecret: process.env.ACCESS_KEY_SECRET,
bucket: process.env.BUCKET,
endpoint: process.env.ENDPOINT,
cdnDomain: process.env.CDN_DOMAIN,
})
ossDownloadHelper.sign('https://example.com/file.png', 60) // 60秒后过期