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

409
Vistas
NodeJs: ¿hay alguna manera de poner imageToBase64 const dentro del método de creación de Sequelize mientras se carga la imagen?

Tengo esta ruta a continuación funcionando bien

 routes.post("/product/new", adminAuth, upload.single("picture"), (req,res) => { var {title, code, price, amount, supplier } = req.body async function convertImage(){ return await imageToBase64(req.file.path); } convertImage().then(async(picture) => { if(picture){ console.log(picture) Product.create({ title: title, slug: slugify(title), code: code, price: price, amount: amount, // picture: picture, supplierId: supplier }).then(() =>{ res.redirect("/admin/products"); }); } }).catch(err => { throw err }); });

Sin embargo, cuando paso la picture variable, aparece el siguiente mensaje de registro:

 UnhandledPromiseRejectionWarning: Error UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1 (node:9735) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Mi pregunta está relacionada con la creación del método Sequelize. ({}), ¿puedo pasar la const desde imageToBase64 adentro? La idea es convertir la imagen cargada a base64 y guardarla en una base de datos.

Aquí está el modelo del producto

 const Product = connection.define('products', { title:{ type: Sequelize.STRING, allowNull: false }, slug: { type: Sequelize.STRING, allowNull: false }, code: { type: Sequelize.STRING, allowNull: false }, price: { type: Sequelize.STRING, allowNull: true }, amount: { type: Sequelize.STRING, allowNull: true }, picture: { type: Sequelize.STRING, allowNull: true }});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

prueba BLOB

 picture: { type: DataTypes.BLOB('long'), get () { let data = this.getDataValue('picture'); return data ? data.toString('base64') : ''; } }
about 4 years ago · Juan Pablo Isaza Denunciar
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