blob: 8a104b7d65a90a50dcc72c785183fab77c184252 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import { Application } from '@feathersjs/express';
import { Params } from '@feathersjs/feathers';
import { S3 } from 'aws-sdk';
import { v4 as uuidv4 } from 'uuid';
export default class Files {
app!: Application;
s3!: S3;
bucket!: string;
async find(params: Params): Promise<string> {
// Return signed upload URL
return this.s3.getSignedUrl('putObject', {
Bucket: this.bucket,
Key: `${params.user?.username}/${uuidv4()}.png`,
ContentType: 'image/*',
Expires: 300,
});
}
setup(app: Application): void {
this.app = app;
this.s3 = new S3({
accessKeyId: process.env.ACCESSKEYID,
secretAccessKey: process.env.SECRETACCESSKEY,
signatureVersion: 'v4',
region: 'eu-central-1'
});
this.bucket = process.env.BUCKET || '';
}
}
|