This content originally appeared on DEV Community and was authored by Leonardo Minora
Códigos-fonte
import { Injectable } from '@nestjs/common';
import { promises as fs } from 'fs';
import * as path from 'path';
@Injectable()
export class ArmazenamentoService {
private readonly dirLocal = path.join(__dirname, '..', 'uploads');
async salvar(imagem: Express.Multer.File): Promise<string> {
const arquivoNome = image.originalname;
await fs.writeFile(path.join(this.dirLocal, arquivoNome), image.buffer);
return arquivoNome;
}
async getImage(arquivoNome: string): Promise<Buffer | null> {
try {
const imagePath = path.join(this.imagesDir, filename);
return await fs.readFile(imagePath);
} catch (error) {
return null;
}
}
}
This content originally appeared on DEV Community and was authored by Leonardo Minora
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
Leonardo Minora | Sciencx (2024-09-16T17:59:19+00:00) Nest – Armazenamento local de upload. Retrieved from https://www.scien.cx/2024/09/16/nest-armazenamento-local-de-upload/
" » Nest – Armazenamento local de upload." Leonardo Minora | Sciencx - Monday September 16, 2024, https://www.scien.cx/2024/09/16/nest-armazenamento-local-de-upload/
HARVARDLeonardo Minora | Sciencx Monday September 16, 2024 » Nest – Armazenamento local de upload., viewed ,<https://www.scien.cx/2024/09/16/nest-armazenamento-local-de-upload/>
VANCOUVERLeonardo Minora | Sciencx - » Nest – Armazenamento local de upload. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/16/nest-armazenamento-local-de-upload/
CHICAGO" » Nest – Armazenamento local de upload." Leonardo Minora | Sciencx - Accessed . https://www.scien.cx/2024/09/16/nest-armazenamento-local-de-upload/
IEEE" » Nest – Armazenamento local de upload." Leonardo Minora | Sciencx [Online]. Available: https://www.scien.cx/2024/09/16/nest-armazenamento-local-de-upload/. [Accessed: ]
rf:citation » Nest – Armazenamento local de upload | Leonardo Minora | Sciencx | https://www.scien.cx/2024/09/16/nest-armazenamento-local-de-upload/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.