Skip to content

Commit

Permalink
docs(nestjs-tools-file-storage): update usage docs [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Jul 12, 2024
1 parent 7aabcb6 commit b12fa2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
33 changes: 21 additions & 12 deletions packages/file-storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { AppService } from './env';
inject: [ConfigService],
useFactory: (configService: ConfigService) => {
const environment = configService.get('NODE_ENV', { infer: true });
if (environment === Environment.Development) {
if (environment === 'development') {
const setup = {
storagePath: configService.get('STORAGE_PATH'),
maxPayloadSize: configService.get('MAX_PAYLOAD_SIZE'),
Expand Down Expand Up @@ -75,19 +75,20 @@ export class AppService {
private readonly fileStorageService: FileStorageService,
) {}

async getFile(): Promise<Uint8Array> {
const filePath = this.configService.get('FILE_PATH');
return this.fileStorage.downloadFile({
filePath,
});
getFile(filePath: string): Promise<Buffer> {
return this.fileStorage.downloadFile({ filePath });
}

setFile(content: string): Promise<void> {
setFile(filePath: string, content: string): Promise<void> {
return this.fileStorage.uploadFile({
filePath: this.configService.get('FILE_PATH'),
filePath,
content,
});
}

deleteFile(filePath: string): Promise<void> {
return this.fileStorage.deleteFile({ filePath });
}
}
```

Expand All @@ -98,14 +99,22 @@ You should also authenticate to external services.

### AWS

I highly recommend configuring the [AWS Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/quick-start-default-idc.html) to manage your AWS credentials for development. You can use the `aws` CLI to authenticate, find more information [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html/).
I highly recommend configuring the [AWS Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/quick-start-default-idc.html) to manage your AWS credentials for development.

> **Note:**
> You can use the `aws` CLI to authenticate, find more information [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html/).
Once done authenticated with the CLI, set the `AWS_PROFILE` environment variable to the profile you want to use.
Once authenticated:

- set the `AWS_PROFILE` environment variable to the profile you want to use
- or set the `AWS_S3_ACCESS_KEY_ID` and `AWS_S3_SECRET_ACCESS_KEY` environment variables.

### Google Cloud

The recommended approach is to setup (Application Default Credentials)[https://cloud.google.com/docs/authentication/provide-credentials-adc#local-dev].
You can use the `gcloud` CLI to authenticate, more information [here](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login).
The recommended approach is to setup [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc#local-dev).

> **Note:**
> You can use the `gcloud` CLI to authenticate, more information [here](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login).
## Troubleshooting

Expand Down
4 changes: 2 additions & 2 deletions packages/file-storage/src/lib/file-storage-google.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class FileStorageGoogle implements FileStorage {
const { storage, bucket } = this.config;
const { options = {}, request } = args;
const filePath = await this.transformFilePath(args.filePath, MethodTypes.READ, request, options);
const [content] = await storage.bucket(bucket).file(filePath).download();
const [content] = await storage.bucket(bucket).file(filePath).download(options);
return content;
}

Expand All @@ -105,7 +105,7 @@ export class FileStorageGoogle implements FileStorage {
const { storage, bucket } = this.config;
const { options = {}, request } = args;
const filePath = await this.transformFilePath(args.filePath, MethodTypes.DELETE, request, options);
await storage.bucket(bucket).file(filePath).delete();
await storage.bucket(bucket).file(filePath).delete(options);
return true;
} catch (error) {
return false;
Expand Down

0 comments on commit b12fa2d

Please sign in to comment.