Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda