# nestjs-alicloud-oss

> Alicloud OSS(Object Storage Service) module for NestJS framework (node.js)

Latest version **1.0.1** (published 2020-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install nestjs-alicloud-oss
pnpm add nestjs-alicloud-oss
yarn add nestjs-alicloud-oss
bun add nestjs-alicloud-oss
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-06-26 |
| First published | 2020-06-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Zhou Zhenzhou |
| Maintainers | zhouzhenzhou |
| Keywords | NestJS, Alicloud, oss, storage, nodejs |

## Links

- npm: https://www.npmjs.com/package/nestjs-alicloud-oss
- Repository: https://github.com/YuchenWell/nestjs-alicloud-oss
- Homepage: https://github.com/YuchenWell/nestjs-alicloud-oss#readme
- Issues: https://github.com/YuchenWell/nestjs-alicloud-oss/issues
- npm.io page: https://npm.io/package/nestjs-alicloud-oss

## Dependencies (1)

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

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-06-26
- 1.0.0 — 2020-06-24

## README

<p align="center">
  <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
</p>

<p align="center">
    <a href="https://www.npmjs.com/package/nestjs-alicloud-oss"><img src="https://img.shields.io/npm/v/nestjs-alicloud-oss.svg" alt="NPM Version" /></a>
    <a href="https://www.npmjs.com/package/nestjs-alicloud-oss"><img src="https://img.shields.io/npm/l/nestjs-alicloud-oss.svg" alt="Package License" /></a>
</p>

English | [简体中文](README-zh_CN.md)

## Description

[Alicloud OSS](https://www.aliyun.com/product/oss) module for [Nest](https://github.com/nestjs/nest) framework (node.js)

## Before Installation

1. Create Alicloud account
2. Purchase OSS. ([read more](https://www.aliyun.com/product/oss))
3. Create bucket, go to **Dashboard > Object Storage Service > Bucket List > Add Bucket**

## Installation

```bash
$ npm install --save nestjs-alicloud-oss
#or
$ yarn add nestjs-alicloud-oss
```

## Documentation

1. Import the `AlicloudOssModule` with the following configuration:

```typescript
import { Module } from '@nestjs/common';
import { AlicloudOssModule } from 'nestjs-alicloud-oss';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [AppService],
  imports: [
    AlicloudOssModule.withConfig({
      options: {
        accessKeyId: '******',
        accessKeySecret: '******',
        region: '******', // the bucket data region location, doc demo used 'oss-cn-beijing'.
        bucket: '******', // the default bucket you want to access, doc demo used 'nest-alicloud-oss-demo'.
      },
    }),
  ],
})
export class AppModule {}
```

> You may provide a default `bucket` name for the whole module, this will apply to all controllers withing this module. You can also provide (override) the `bucket` in the controller, for each route.

## Examples

### Store a file using the default bucket

```typescript
import { Controller, Logger, Post, UploadedFile, UseInterceptors } from '@nestjs/common';
import { AlicloudOssFileInterceptor, UploadedFileMetadata } from 'nestjs-alicloud-oss';

@Controller()
export class AppController {
  @Post('upload')
  @UseInterceptors(AlicloudOssFileInterceptor('file'))
  UploadedFileUsingInterceptor(
    @UploadedFile()
    file: UploadedFileMetadata,
  ) {
    console.log(file.objectUrl);
    // http://nest-alicloud-oss-demo.oss-cn-beijing.aliyuncs.com/filename
  }
}
```

### Store a file using a specific bucket and folder

```typescript
import { Controller, Logger, Post, UploadedFile, UseInterceptors } from '@nestjs/common';
import { AlicloudOssFileInterceptor, UploadedFileMetadata } from 'nestjs-alicloud-oss';

@Controller()
export class AppController {
  @Post('upload2')
  @UseInterceptors(
    AlicloudOssFileInterceptor('file', null, {
      { folder: 'x/y/z', bucket: 'nest-alicloud-oss-demo2' },
    }),
  )
  UploadedFilesUsingInterceptor(
    @UploadedFile()
    file: UploadedFileMetadata,
  ) {
    console.log(file.objectUrl);
    // http://nest-alicloud-oss-demo2.oss-cn-beijing.aliyuncs.com/x/y/z/filename
  }
}
```

### Store a file using a custom filename and custom bucket

```typescript
import { Controller, Logger, Post, UploadedFile, UseInterceptors } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { AlicloudOssService, UploadedFileMetadata } from 'nestjs-alicloud-oss';

@Controller()
export class AppController {
  constructor(private readonly ossService: AlicloudOssService) {}

  @Post('upload3')
  @UseInterceptors(FileInterceptor('file'))
  async UploadedFilesUsingService(
    @UploadedFile()
    file: UploadedFileMetadata,
  ) {
    file = {
      ...file,
      customName: 'customFilename.txt',
      folder: 'a/b/c',
      bucket: 'nest-alicloud-oss-demo3'
    };
    const url = await this.ossService.upload(file);

    console.log(url)
    // http://nest-alicloud-oss-demo3.oss-cn-beijing.aliyuncs.com/a/b/c/customFilename.txt

    console.log(file.objectUrl);
    // http://nest-alicloud-oss-demo3.oss-cn-beijing.aliyuncs.com/a/b/c/customFilename.txt
  }
}
```

### License

The [MIT](LICENSE) License.

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