Saber2pr's Blog

在nodejs上使用ossApi

  1. 安装 ali-oss:

ali-oss 文档

yarn add ali-oss
  1. 连接 OSS:
const client = new OSS({
  accessKeyId: 'xxx',
  accessKeySecret: 'yyy',
  bucket: 'your-bucket',
  region: 'oss-cn-hangzhou',
})
  1. 上传文件

put(路径,Buffer)

const buf = await promisify(readFile)('./hello.txt')
await client.put(`/dir/test.txt`, buf)