src/app.controller.ts
Methods |
| getDownloadURL |
getDownloadURL(filename: string, bucketName: string)
|
Decorators :
@Get('getDownloadURL')
|
|
Defined in src/app.controller.ts:62
|
|
Sample API to get temporary download URL
Returns :
any
|
| getHello |
getHello()
|
Decorators :
@Get()
|
|
Defined in src/app.controller.ts:24
|
|
Returns :
string
|
| uploadFile |
uploadFile(file: Express.Multer.File, filename: string, bucketName: string)
|
Decorators :
@Post('uploadFile/:filename')
|
|
Defined in src/app.controller.ts:49
|
|
Sample function for file upload filename is expected to be absolute path wrt bucket
Returns :
any
|
| whoami | ||||
whoami(req)
|
||||
Decorators :
@Get('whoami')
|
||||
|
Defined in src/app.controller.ts:70
|
||||
|
Parameters :
Returns :
{ id: any; }
|
import {
Controller,
Get,
Request,
Post,
UseInterceptors,
UploadedFile,
Param,
} from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import { ApiBearerAuth, ApiBody, ApiConsumes } from "@nestjs/swagger";
import { AppService } from "./app.service";
import { MinioProvider } from "./providers/minio/minio.provider";
@ApiBearerAuth("access-token") // this appends authorization header for swagger UI
@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
private readonly storageProvider: MinioProvider,
) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
/**
* Sample function for file upload
* filename is expected to be absolute path wrt bucket
* @returns
*/
@Post("uploadFile/:filename")
@UseInterceptors(FileInterceptor("file"))
@ApiConsumes("multipart/form-data")
@ApiBody({
type: "multipart/form-data",
required: true,
schema: {
type: "object",
properties: {
file: {
type: "string",
format: "binary",
},
},
},
})
uploadFile(
@UploadedFile("file") file: Express.Multer.File,
@Param("filename") filename: string,
@Param("bucketName") bucketName: string,
) {
return this.storageProvider.uploadFile(bucketName, filename, file.buffer);
}
/**
* Sample API to get temporary download URL
* @returns
*/
@Get("getDownloadURL")
getDownloadURL(
@Param("filename") filename: string,
@Param("bucketName") bucketName: string,
) {
return this.storageProvider.getTemporarySharedURL(bucketName, filename);
}
@Get("whoami")
whoami(@Request() req) {
// this function currently returns just logged in user emai
// req.user object will contain entire decoded jwt
// request will not reach here till it has passed AuthGuards
return {
id: req.user.id,
};
}
}