Validacion y restriccion de archivos + almacenamiento en carpeta
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
DROP VIEW "public"."v_product_store";--> statement-breakpoint
|
||||
ALTER TABLE "products" ADD COLUMN "gallery" text[] DEFAULT '{}'::text[] NOT NULL;--> statement-breakpoint
|
||||
CREATE VIEW "public"."v_product_store" AS (
|
||||
select p.id as product_id, p.title, p.description, p.price, p.stock, p.url_img, p.gallery, p.address, p.status, p.user_id, u.fullname, u.email, u.phone
|
||||
from products p
|
||||
left join auth.users as u on u.id = p.user_id);
|
||||
1550
apps/api/src/database/migrations/meta/0007_snapshot.json
Normal file
1550
apps/api/src/database/migrations/meta/0007_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -50,6 +50,13 @@
|
||||
"when": 1752507413748,
|
||||
"tag": "0006_real_tyger_tiger",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "7",
|
||||
"when": 1754420096323,
|
||||
"tag": "0007_curved_fantastic_four",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -16,7 +16,8 @@ export async function seedProducts(db: NodePgDatabase<typeof schema>) {
|
||||
address:"Calle 1",
|
||||
status:'PUBLICADO', // PUBLICADO, AGOTADO, BORRADOR
|
||||
urlImg:'apple.avif',
|
||||
userId:1
|
||||
userId:1,
|
||||
gallery: ["Pruebas"]
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
import { Controller, Post, UploadedFiles, UseInterceptors } from '@nestjs/common';
|
||||
import { Controller, Post, UploadedFiles, UseInterceptors, Body } from '@nestjs/common';
|
||||
import { FilesInterceptor } from '@nestjs/platform-express';
|
||||
import { PicturesService } from './pictures.service';
|
||||
|
||||
@@ -9,13 +8,14 @@ export class PicturesController {
|
||||
|
||||
@Post('upload')
|
||||
@UseInterceptors(FilesInterceptor('urlImg'))
|
||||
async uploadFile(@UploadedFiles() files: Express.Multer.File[]) {
|
||||
console.log(files);
|
||||
|
||||
async uploadFile(@UploadedFiles() files: Express.Multer.File[], @Body() body: any) {
|
||||
// Aquí puedes acceder a los campos del formulario
|
||||
// console.log('Archivos:', files);
|
||||
// console.log('Otros campos del formulario:', body);
|
||||
|
||||
const result = await this.picturesService.saveImages(files);
|
||||
console.log(result);
|
||||
|
||||
// const result = await this.picturesService.saveImages(files);
|
||||
// console.log(result);
|
||||
|
||||
return {data: ["result"]}
|
||||
return { data: result };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,21 +14,20 @@ export class PicturesService {
|
||||
|
||||
const picturesPath = join(__dirname, '..', '..', '..', '..', 'uploads','pict');
|
||||
|
||||
console.log(picturesPath);
|
||||
|
||||
let images : string[] = [];
|
||||
|
||||
console.log(file);
|
||||
|
||||
|
||||
let count = 0;
|
||||
|
||||
// file.forEach(async (file) => {
|
||||
// // count++
|
||||
// // const fileName = `${Date.now()}-${count++}-${file.originalname}`;
|
||||
// // console.log(fileName);
|
||||
// // const filePath = join(picturesPath, fileName);
|
||||
// // await writeFile(filePath, file.buffer);
|
||||
// // images.push(fileName);
|
||||
// });
|
||||
file.forEach(async (file) => {
|
||||
count++
|
||||
const fileName = `${Date.now()}-${count}-${file.originalname}`;
|
||||
images.push(fileName);
|
||||
// console.log(fileName);
|
||||
const filePath = join(picturesPath, fileName);
|
||||
await writeFile(filePath, file.buffer);
|
||||
});
|
||||
// return [file[0].originalname]
|
||||
return images;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user