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

168
Views
Image cannot be an array or an object

I am developing a project which consists of publishing a post and being able to upload a user image. I used JS for Front and NodeJs for Back (Multer for uploading images).I have an error for making a post and uploading an image to my DDBB in Mysql. I created the posts without any errors, but when I implement ability of sending an image I got this error:

string violation: image cannot be an array or an object

Code:

//Here call the action from PostActions
const addPost = (body) => dispatch(createPostAction(body));

const userId = props.credentials?.user.id

//Formate the picture
const formdata = new FormData();
formdata.append('image', image, userId);
const user = post.user;
const token = post.token;

//Create the post
addPost({
    title,
    content,
    image,
    userName: post.name,
    lastName: post.lastName,
    date: new Date(),
    userId: user.id,
    token: token,
});
//My route
router.post("/", authenticate, fileUpload, async(req, res) => {
    try {
        const id = req.body;
        const image = req.file;
        res.json(await postControllers.makePost(id, image))
    } catch (error) {
        return res.status(500).json({
           message: error.message
        });
    }
});
//My controller
async makePost(post) {
    return Post.create(post);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't recommend storing images in a mysql database, or any database in general.

The most common way to handle image uploads it to store an image into a file storage system like Amazon S3 or Cloudfront, and then store the image url you receive (which is usually the file path to the image, and is a string), in the database.

This is due to both performance and bandwidth optimization.

However, if you want to store it in your MySQL database, you need to store it as a blob. Ex:

CREATE TABLE 'test'.'pic' (
  'pic' INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  'img' LONGBLOB NOT NULL,
  PRIMARY KEY ('pic')
)

This string violation could be due to MySQL expecting a string (path to an image), and is not configured to receive a blob type.

To test, try passing in a string as the value of the image key, and see if adding the post succeeds.

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