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

233
Views
agregar el archivo de imagen pegado en formdata siempre está vacío

Estoy pegando una imagen y luego creándola como un objeto de File , luego la agrego a formData y se muestra como vacía, no se agrega ningún archivo.

evento de pegado:

 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); }

Compruebo image.data y muestra que el objeto File está allí. Ahora que tengo image.data como archivo, lo cargo en formData :

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

imprimiendo imageFile :

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

devoluciones:

 image, {} username, "Chris"

¿Qué estoy haciendo mal?

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!