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

163
Views
await only valid in async function meanwhile i already put "async" in the function

It says that await only valid for async function but i already put the async word before the (req,res,next) , did i code it wrong?

const axios = require("axios");
const FormData = require("form-data");
const imageKit = async (req, res, next) => {
if (req.files) {
  try {
    const files = req.files;
    const values = Object.values(files);
    values.map((perArray) => {
      perArray.forEach((item) => {
        if (item.mimetype === "image/jpeg" || item.mimetype === "image/png") {
          const newForm = FormData();
          const encodedFile = item.buffer.toString("base64");
          newForm.append("file", encodedFile);
          newForm.append("fileName", item.originalname);
          const encodedKey = Buffer.from(
            process.env.IMAGE_KIT + ":"
          ).toString("base64");
          const result = await axios({
            method: "POST",
            url: "https://upload.imagekit.io/api/v1/files/upload",
            data: newForm,
            headers: {
              ...newForm.getHeaders(),
              Authorization: `Basic ${encodedKey}`,
            },
          });
        }
      });
    });
  } catch (error) {}
}
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your function that you pass to forEach is not async and it is not recommended to use async in forEach.

Using async/await with a forEach loop

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!