feat: upload module
This commit is contained in:
parent
202e67dbe7
commit
86398fc2b3
|
|
@ -1,8 +1,8 @@
|
|||
import { Global, Module } from '@nestjs/common';
|
||||
import {MulterModule} from "@nestjs/platform-express";
|
||||
import {diskStorage} from "multer";
|
||||
import {mkdirSync} from 'fs';
|
||||
import {extname} from 'path';
|
||||
import { MulterModule } from '@nestjs/platform-express';
|
||||
import { diskStorage } from 'multer';
|
||||
import { mkdirSync } from 'fs';
|
||||
import { extname } from 'path';
|
||||
|
||||
const storage = diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
|
|
@ -20,7 +20,10 @@ const storage = diskStorage({
|
|||
},
|
||||
filename: (req, file, cb) => {
|
||||
// Generate a unique filename here if needed
|
||||
const randomName = Array(32).fill(null).map(() => (Math.round(Math.random() * 16)).toString(16)).join('');
|
||||
const randomName = Array(32)
|
||||
.fill(null)
|
||||
.map(() => Math.round(Math.random() * 16).toString(16))
|
||||
.join('');
|
||||
cb(null, `${randomName}${extname(file.originalname)}`);
|
||||
},
|
||||
});
|
||||
|
|
@ -29,7 +32,7 @@ const storage = diskStorage({
|
|||
@Module({
|
||||
imports: [
|
||||
MulterModule.register({
|
||||
storage
|
||||
storage,
|
||||
}),
|
||||
],
|
||||
get exports() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue