# @lantsang/nestjs-aliyun-oss

> 阿里云OSS nestjs封装

Latest version **0.0.5** (published 2020-11-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @lantsang/nestjs-aliyun-oss
pnpm add @lantsang/nestjs-aliyun-oss
yarn add @lantsang/nestjs-aliyun-oss
bun add @lantsang/nestjs-aliyun-oss
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2020-11-17 |
| First published | 2020-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 233.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Iric |
| Maintainers | iricbing, lantsang |
| Keywords | nestjs, 阿里云 oss, typescript |

## Links

- npm: https://www.npmjs.com/package/@lantsang/nestjs-aliyun-oss
- npm.io page: https://npm.io/package/@lantsang/nestjs-aliyun-oss

## Dependencies (1)

- [ali-oss](https://npm.io/package/ali-oss.md) ^6.11.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2020-11-17
- 0.0.4 — 2020-10-27
- 0.0.3-test1 — 2020-10-27
- 0.0.3-fix5 — 2020-10-27
- 0.0.3-fix4 — 2020-10-27
- 0.0.3-fix3 — 2020-10-27
- 0.0.3-fix2 — 2020-10-27
- 0.0.3-fix1 — 2020-10-27
- 0.0.3 — 2020-10-27
- 0.0.2 — 2020-10-27
- 0.0.1 — 2020-10-26

## README

# nestjs 阿里云OSS插件

注意：<font color="#dd0000">仍在开发中，目前仅在内部使用</font><br /> 

## 使用说明

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

## 安装

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

## 引入

``` typescript
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上传文件

``` typescript
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;
  }
}
```

### 检测文件是否存在

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

### 删除文件

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

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

### 拷贝文件

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

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

---
_Source: https://npm.io/package/@lantsang/nestjs-aliyun-oss · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
