0.0.5 • Published 3 years ago

@lantsang/nestjs-aliyun-oss v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

nestjs 阿里云OSS插件

注意:仍在开发中,目前仅在内部使用

使用说明

  • 外部人员仅供参考,请不要用于生产环境,因此导致的事故后果请自行承担。
  • TS target es2019
  • 支持集群

安装

$ npm i @lantsang/nestjs-aliyun-oss or $ yarn add @lantsang/nestjs-aliyun-oss 推荐使用yarn

引入

import { AliOSSModule } from '@lantsang/nestjs-aliyun-oss'

@Module({
  imports: [
    AliOSSModule.register({
      region: 'oss-cn-beijing',
      endpoint: 'https://oss-cn-beijing.aliyuncs.com', 
      bucket: 'vue-test-iric',
      accessKeyId: '********',
      accessKeySecret: '******'
    })
  ]
})
export class AppModule { }

方法使用

Put上传文件

import { Inject, Injectable } from '@nestjs/common';
import { AliOSSService } from "@lantsang/nestjs-aliyun-oss";

@Injectable()
export class TestService {
  constructor(private readonly aliOSSService: AliOSSService) {}

  /**
   * 上传文件到OSS上,返回oss中文件url地址
   * @param remotePath OSS远端路径, 例如:'upload/123.txt'
   * @param localPath 文件本地路径,绝对路径,使用path.join()方法获取
   */
  async upload(remotePath: string, localPath: string):Promise<string>{
    const { name, url, res } = await this.aliOSSService.putUpload(remotePath,localPath);
    return url;
  }
}

检测文件是否存在

const exist = await this.aliOSSService.fileExist('upload/123.txt');

删除文件

注意: 删除文件首先先保证oss中存在此文件,如果不存在会抛错,删除并不会返回删除成功与否结果,这个问题具体看代码中注释。

await this.aliOSSService.delete('upload/123.txt');

拷贝文件

注意: 如果目标文件不存在会报错。

const copyResult = await this.aliOSSService.copy('upload/123.txt','upload/123_copy.txt');
0.0.5

3 years ago

0.0.4

4 years ago

0.0.3-test1

4 years ago

0.0.3-fix5

4 years ago

0.0.3-fix3

4 years ago

0.0.3

4 years ago

0.0.3-fix4

4 years ago

0.0.3-fix1

4 years ago

0.0.3-fix2

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago