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

267
Views
API resolved without sending a response for /api/image/Upload, this may result in stalled requests

I am using next js and have this function on a page to call an api to upload an image i am not sure where to add in a response this does work and uploads the image to my aws cdn.

async function handleProductImageUpload(e) {
        const file = e.target.files[0];
        const formData = new FormData();
        formData.append("file", file);
        try {
            const upload = await fetch(`/api/image/Upload`, {
                method: "POST",
                body: formData,
                "Content-Type": "image/jpg",
            });
            const response = await upload.json();
            response && console.log(response.data.Location);
            setProductImages([...productImages, response.data.Location]);
        } catch (error) {
            upload.status(error.status).json(error.response.data);
        }
    }

code for /api/image/Upload

import AWS from "aws-sdk";

export default async function handler(req, res) {
    // get the image data
    let image = req.body;

    // create S3 instance with credentials
    const s3 = new AWS.S3({
        endpoint: new AWS.Endpoint("https://nyc3.digitaloceanspaces.com/"),
        accessKeyId: process.env.ACCESS_KEY_ID,
        secretAccessKey: process.env.ACCESS_SECRET_KEY,
        region: "us-west-2",
    });

    // create parameters for upload
    const uploadParams = {
        Bucket: process.env.DOS3_BUCKET,
        Key: req.query.file,
        Body: image,
        ContentType: "image/jpeg",
        ACL: "public-read",
    };
    //console.log(uploadParams);
    // execute upload
    let result = s3.upload(uploadParams, (err, data) => {
        if (err) return console.log("reject", err);
        else return console.log("resolve", data);
    });
    res.status(200).send({ result });
}
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!