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

123
Vistas
Upload image buffer to Amazon EC2 through cloudfront using nodejs and multer

I saw this great introduction and I implemented it similarly, but I implemented it well on the local server (development server), but Amazon ec2 server using cloudfront generates 502 error.

After checking the console, it seems that long data with buffer is not stored in the database. I don't know why it works on the local server but not on ec2. Is cloudfront the problem? How can I find a solution?

const express = require('express');
const router = express.Router();
const Post = require('../models/Post');

const multer = require('multer');
const fs = require('fs');
var path = require('path');

const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/');
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname);
  },
});
const upload = multer({ storage });

// blog post creation
router.post('/', upload.single('image'), (req, res) => {
  const { title, description, category, md } = req.body;
  const requestPost = {
    title,
    description,
    category,
    content: md,
    image: {
      data: fs.readFileSync(
        path.join(__dirname, '..', 'uploads/' + req.file.filename)
      ),
      contentType: 'image/png',
    },
  };

// the below codes doesn't work. console.log() in this code didn't work
  const post = new Post(requestPost);
  post.save((err, post) => {
    if (err) return res.status(400).json({ trial: false, err });

    res.status(200).json({ trial: true, post });
  });
});

enter image description here

I think the size of the ArrayBuffer in the image is too large for cloudfront to communicate with MongoDB atlas.

If my guess is correct, I wonder how cloudfront interferes with this when the database and ec2 communicate directly.

Please let me know if you don't understand this question. I'm frustrated because I can't figure out what the problem is. Have a nice day....!

about 4 years ago · Juan Pablo Isaza
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