0.0.3 • Published 12 months ago

@scholten.dev/file-store v0.0.3

Weekly downloads
-
License
-
Repository
-
Last release
12 months ago

File store

Typescript package which interfaces the filestore api.

Usage

Usage in plain nodejs

const fileStore = new FileStore('domainname.com', 'userId', 'api-key');

const file = await fileStore.getFile('myfile.jpg');
const text = arrayBufferToText(file);
const buffer = arrayBufferToBuffer(file);

const filePath = await fileStore.saveFile('myfile.jpg', 'image/jpeg', bufferToBase64(buffer));

await fileStore.deleteFile('myfile.jpg);

Usage in nestjs

import { Global, Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { FileStore } from '@scholten.dev/file-store';

export enum Globals {
  FILE_STORE = 'filestore',
}

@Global()
@Module({
  providers: [
    {
      provide: Globals.FILE_STORE,
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) =>
        new FileStore(
          configService.getOrThrow('FILESTORE_DOMAIN'),
          configService.getOrThrow('FILESTORE_USERID'),
          configService.getOrThrow('FILESTORE_APIKEY'),
        ),
    },
  ],
  exports: [Globals.FILE_STORE],
})
export class GlobalModule {}
0.0.3

12 months ago

0.0.2

1 year ago

0.0.1

1 year ago