Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

189
Vistas
I always get a problem if the image is already created

This project changes the image sizes this project is using a library called sharp, but at first, if the image is created for the first time, it does not cause problems, but it always shows me that problem if it was already created. In imageProcessing.ts File

import { Request, Response } from "express";
import fs, { promises as fsPromises } from 'fs';
import resizingTheImage from "./resizingTheImage";

const imageProcessing = async(req: Request, res: Response, next: Function): Promise<void | string> => {
    const widthValue = <string>req.query.width;
    const heightValue = <string>req.query.height;
    const nameFileValue = <string>req.query.namefile;

    const outputDir = `../../images/imageOutput/${nameFileValue}${widthValue}_${heightValue}.jpg`;

    const makeDir = async (): Promise<void> => {
        await fsPromises.mkdir('./images/imageOutput');
    };

    const imageProcessing = async (): Promise<void> => {
        try {
            await resizingTheImage(widthValue, heightValue, nameFileValue);
        } catch {
            res.send('There is a problem with the image processing');
        }
    };

    if (fs.existsSync(outputDir)) {
        return outputDir;
    } else {
        makeDir();
        await imageProcessing();
    }

    next();
}

export default imageProcessing;

In resizingTheImage.ts File

import sharp from "sharp";

const resizingTheImage = async (imageWidth: string, imageHeight: string, fileName: string): Promise<void> => {
    const imageDir: string = `./images/${fileName}.jpg`;
    const outputDir: string = `./images/imageOutput/${fileName}${imageWidth}_${imageHeight}.jpg`;

    if (isNaN(parseInt(imageWidth) && parseInt(imageHeight)) && fileName) {
        console.log("the inputs is Invalid")
    } else {
        await sharp(imageDir)
            .resize(parseInt(imageWidth), parseInt(imageHeight))
            .toFile(outputDir);
    }
}

export default resizingTheImage;

In error

[Error: EEXIST: file already exists, mkdir 'E:\Image Processing API\images\imageOutput'] {
  errno: -4075,
  code: 'EEXIST',
  syscall: 'mkdir',
  path: 'E:\\Image Processing API\\images\\imageOutput'
}
over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda