nodejs上传本地文件到OSS

nodejs上传本地文件到OSS

本文档介绍如何将本地文件上传到 OSS。
https://help.aliyun.com/document_detail/111265.html

1本地文件上传到 OSS

通过put接口将本地文件上传到 OSS:

let OSS = require('ali-oss')

let client = new OSS({
  region: '',
  accessKeyId: '',
  accessKeySecret: '',
  bucket: '',
});

async function put () {
  try {
    let result = await client.put('object-name', 'local-file');
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

put();

2内存中的内容上传到 OSS

您可以通过put接口简单地将本地内存中的内容上传到 OSS:

let OSS = require('ali-oss');

let client = new OSS({
  region: '',
  accessKeyId: '',
  accessKeySecret: '',
  bucket: '',
});

async function putBuffer () {
  try {
    let result = await client.put('object-name', new Buffer('hello world'));
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

putBuffer();

你可能感兴趣的:(nodejs上传本地文件到OSS)