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

225
Views
appending pasted image file into formdata is always empty

I'm pasting an image and then creating it as a File object, afterwards I append it into formData and it shows as empty, no file is appended.

pasting event:

const handlePaste = async function (e) {
        if (!e.clipboardData.files.length) {
            return console.log('no images sent');
        }

        const clipboardItems = e.clipboardData.items;
        const items = [].slice.call(clipboardItems).filter(function (item) {
            // Filter the image items only
            return item.type.indexOf('image') !== -1;
        });

        if (items.length === 0) {
            return;
        }

        const pastedImageFile = items[0].getAsFile();

        const image = {
            preview: URL.createObjectURL(pastedImageFile),
            data: pastedImageFile,
        }

        setPastedImage(image);
        setSendingPasted(true);
    }

I check image.data and it shows that the File object is there, Now that I have image.data as a file, I load it into formData:

const imageFile = new FormData();
imageFile.append('image', pastedImage.data, pastedImage.data.name);
imageFile.append('username', 'Chris');

printing out imageFile:

for (var pair of imageFile.entries()) {
    console.log(pair[0]+ ', ' + JSON.stringify(pair[1]));
}

returns:

image, {}
username, "Chris"

What am I doing wrong?

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!