Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!