Skip to content

Commit 184830c

Browse files
committed
Add GIF files support; added file size and type validation (max=5Mb)
1 parent e14b7f9 commit 184830c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/app.controller.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Param,
99
Post,
1010
Query, UploadedFile, UseInterceptors,
11-
Headers, UseGuards, Request
11+
Headers, UseGuards, Request, ParseFilePipe, MaxFileSizeValidator, FileTypeValidator
1212
} from '@nestjs/common';
1313
import {ApiBearerAuth, ApiTags} from '@nestjs/swagger';
1414
import { ConfigService } from '@nestjs/config';
@@ -113,15 +113,22 @@ export class AppController {
113113
@UseInterceptors(FileInterceptor('file'))
114114
async uploadImage(
115115
@Request() req,
116-
@UploadedFile() uploadedFile: Express.Multer.File,
116+
@UploadedFile(
117+
new ParseFilePipe({
118+
validators: [
119+
new MaxFileSizeValidator({ maxSize: 5 * 1024 * 1024 }),
120+
new FileTypeValidator({ fileType: '.(png|jpeg|jpg|gif)' }),
121+
]
122+
})
123+
) file: Express.Multer.File,
117124
@Headers() headers
118125
) {
119126
if(!req.user) {
120127
throw new BadRequestException('InvalidJWT')
121128
}
122129
const { address } = plainToInstance(JwtUserAccount, req.user)
123130
const uuid = uuidv4()
124-
const imageUrl = await this.gCloudService.uploadImage(uploadedFile, uuid)
131+
const imageUrl = await this.gCloudService.uploadImage(file, uuid)
125132
this.logger.log(`Image uploaded, imageUrl=${imageUrl}, userAddress=${address}`)
126133
return imageUrl
127134
}

src/gcloud/gcloud.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class GcloudService {
1818

1919
public async uploadImage(uploadedFile: Express.Multer.File, filename: string) {
2020
const bucket = this.storage.bucket('pump-fun-metadata')
21-
const storageFileUrl = `images/${filename}.jpg`
21+
const storageFileUrl = `images/${filename}`
2222
const file = bucket.file(storageFileUrl)
2323
await file.save(uploadedFile.buffer)
2424
return `https://storage.googleapis.com/pump-fun-metadata/${storageFileUrl}`

0 commit comments

Comments
 (0)