# nestjs-azure-storage

Latest version **1.1.3** (published 2023-03-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install nestjs-azure-storage
pnpm add nestjs-azure-storage
yarn add nestjs-azure-storage
bun add nestjs-azure-storage
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2023-03-20 |
| First published | 2023-03-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 20 |
| Unpacked size | 21.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | kwabia |
| Keywords | storage, azure, azurestorage, @nestjsazurestorage, nestjs, nestjs azure storage, nestjs-azure-storage, storage-blog, nestjs-azure, nestjs-storage-blob |

## Links

- npm: https://www.npmjs.com/package/nestjs-azure-storage
- npm.io page: https://npm.io/package/nestjs-azure-storage

## Dependencies (20)

- [joi](https://npm.io/package/joi.md) ^17.8.4
- [jest](https://npm.io/package/jest.md) ^29.5.0
- [rxjs](https://npm.io/package/rxjs.md) ^7.8.0
- [axios](https://npm.io/package/axios.md) ^1.3.4
- [eslint](https://npm.io/package/eslint.md) ^8.36.0
- [rimraf](https://npm.io/package/rimraf.md) ^4.4.0
- [uuidv4](https://npm.io/package/uuidv4.md) ^6.2.13
- [ts-jest](https://npm.io/package/ts-jest.md) ^29.0.5
- [prettier](https://npm.io/package/prettier.md) ^2.8.4
- [typescript](https://npm.io/package/typescript.md) ^5.0.2
- [@types/jest](https://npm.io/package/@types/jest.md) ^29.5.0
- [@types/node](https://npm.io/package/@types/node.md) ^18.15.3
- [jest-sorted](https://npm.io/package/jest-sorted.md) ^1.0.14
- [@nestjs/axios](https://npm.io/package/@nestjs/axios.md) ^2.0.0
- [@types/multer](https://npm.io/package/@types/multer.md) ^1.4.7
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^9.3.10
- [@nestjs/config](https://npm.io/package/@nestjs/config.md) ^2.3.1
- [@azure/storage-blob](https://npm.io/package/@azure/storage-blob.md) ^12.13.0
- [eslint-config-prettier](https://npm.io/package/eslint-config-prettier.md) ^8.7.0
- [@nestjs/platform-express](https://npm.io/package/@nestjs/platform-express.md) ^9.3.10

## 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.1.3 (latest) — 2023-03-20
- 1.1.2 — 2023-03-20
- 1.1.1 — 2023-03-20
- 1.0.9 — 2023-03-19
- 1.0.6 — 2023-03-18
- 1.0.5 — 2023-03-18
- 1.0.4 — 2023-03-18
- 1.0.3 — 2023-03-18

## README

<p align="center">
  <img
    src="https://intellipaat.com/blog/wp-content/uploads/2019/06/Graphics-01.jpg"
    width="250"
  />
</p>

<h1 align="center">NestJS Azure Storage</h1>

<p align="center">
  <strong>Wrapper for NestJS Azure Storage</strong>
</p>



> Nestjs-azure-storage is a tiny wrapper on top of azure storage sdks that makes life easier when uploading and deleting files

This module makes it easier to deal with Azure Storage  when using Nest.js!

**docs**: https://github.com/KwobiaMtech/nestjs-azure-storage

---

Let's get started!

```sh

npm i nestjs-azure-storage

yarn add nestjs-azure-storage
```

You'll need to add `nestjs-azure-storage` to your module,
which you can do like this:

```typescript
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigType } from '@nestjs/config';
import { AzureStorageModule, AzureStorageOptions } from 'nestjs-azure-storage';

@Module({
  imports: [
      ConfigModule.forRoot({
        envFilePath: ['.env'],
        isGlobal: true,
        load: [globalConfig],
      }),
      AzureStorageModule.forRootAsync({
        useFactory: async (config: ConfigType<typeof globalConfig>) => {
          const opts = {
            containerName: config.azure.container,
            connectionString: config.azure.connectionString,
          } as AzureStorageOptions;
          return opts;
        },
        inject: [globalConfig.KEY],
    }),
  ],

})
export class AppModule {}
```

Another way to call  nestjs-azure-storage in your module can be seen below:

```typescript
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigType } from '@nestjs/config';
import { AzureStorageModule, AzureStorageOptions } from 'nestjs-azure-storage';

@Module({
  imports: [
      ConfigModule.forRoot({
        envFilePath: ['.env'],
        isGlobal: true,
        load: [globalConfig],
      }),
      AzureStorageModule.forRoot({
        containerName: process.env.containerName,
        connectionString: process.env.connectionString
    })
  ],

})
export class AppModule {}
```

You can structure your controller as shown below to take advantage of the Azure Storage package:

```typescript
import { AppService } from './app.service';
import {
  Body,
  Controller,
  Delete,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';

import { BlobDeleteIfExistsResponse } from '@azure/storage-blob';
import { FileInterceptor } from '@nestjs/platform-express';


@Controller()
export class AppController {
  constructor(private service: AppService) {}

  @Post('upload/file')
  @UseInterceptors(FileInterceptor('file'))
  async uploadFile(
    @UploadedFile() file: Express.Multer.File,
    @Body() req: any,
  ): Promise<{name: string, url: string}> {
    if (!file) throw new Error('File not found');
    file = {
      ...file,
      originalname: file.originalname,
    };
    return await this.service.uploadFile(file);
  }

  @Delete('delete/file')
  async deleteFile(
    @Body() data: {name: string},
  ): Promise<BlobDeleteIfExistsResponse> {
    if (!data.name) throw new Error('File name is required');
    return await this.service.deleteFile(data.name);
  }
}

```


To use azure storage service, you will need to inject the service into your custom service class as shown below 

```typescript
import { AzureStorageService } from 'nestjs-azure-storage';

constructor(
  private storage: AzureStorageService
) {}

```


To implement Azure storage service in your custom service class, you can structure your service as show below

```typescript

import { Injectable } from '@nestjs/common';
import { AzureStorageService } from 'nestjs-azure-storage';
import { BlobDeleteIfExistsResponse } from "@azure/storage-blob";

@Injectable()
export class AppService {
  constructor(private storage: AzureStorageService){}

  async uploadFile(file: Express.Multer.File): Promise<{name: string, url: string}> {
   return this.storage.uploadFile(file);
  }

  async deleteFile(fileName: string): Promise<BlobDeleteIfExistsResponse> {
    return this.storage.deleteFile(fileName);
  }
  
}

```


Apart from this README, you can find examples of using the library in the following places:

- [Example usage][]

[example usage]:  https://github.com/KwobiaMtech/nestjs-azure-storage/tree/main/example/src



This project is [MIT Licensed](LICENSE).

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