Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roitinnovation/roit-storage
Library to connect with Google Cloud Storage on Typescript
https://github.com/roitinnovation/roit-storage
cloud gcp nestjs nodejs storage typescript
Last synced: about 2 months ago
JSON representation
Library to connect with Google Cloud Storage on Typescript
- Host: GitHub
- URL: https://github.com/roitinnovation/roit-storage
- Owner: roitinnovation
- License: mit
- Created: 2021-03-07T18:01:26.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-23T20:15:41.000Z (almost 4 years ago)
- Last Synced: 2024-11-20T12:25:08.625Z (about 2 months ago)
- Topics: cloud, gcp, nestjs, nodejs, storage, typescript
- Language: TypeScript
- Homepage:
- Size: 43 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ROIT Storage
### Usage for Google Cloud Storage
In the `env.yaml` file add the `googleStorageCredential{}` attribute, with the number of folders inside the {}:
```yaml
dev:
googleStorageCredential{5}: my-credential.json
```Inject in your desired class:
```typescript
import { GoogleCloudHandler } from '@roit/roit-storage'constructor(
private readonly googleCloudHandler: GoogleCloudHandler
) {}
```To use the `retrieveFromStorage` method:
```typescript
const filePath = 'path/from/my/file'
const bucketName = 'my-files-bucket'const url = await this.googleCloudHandler.retrieveFromStorage(filePath, bucketName)
console.log(url) // outputs https://storage.googleapis.com/...
```To use the `getSignedUrl` method:
```typescript
const filePath = 'path/from/my/file'
const bucketName = 'my-files-bucket'const url = await this.googleCloudHandler.getSignedUrl(filePath, bucketName)
console.log(url)
```The `getSignedUrl` method returns a URL from Google that you need to perform a HTTP POST with the binary encoded file you want to upload, here is a example in Insomnia:
![insomnia-example](./insomnia-example.png)
### Nestjs Usage
In Nestjs, don't forget to add the `GoogleCloudHandler` on the `AppModule` as a provider:
```typescript
@Module({
imports: [],
controllers: [],
providers: [
GoogleCloudHandler
],
})
export class AppModule { }
```