Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda