question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Corrupt image when uploading

See original GitHub issue

Support plan

  • which support plan is this issue covered by? (e.g. Community, Sponsor, or Enterprise): community
  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: v14.0.0
  • module (formidable) version: 2.0.0-canary.20200504.1
  • environment (e.g. node, browser, native, OS): node with Next.Js
  • used with (i.e. popular names of modules): Next.js
  • any other relevant information: I use the api routing from Next.js

What are you trying to achieve or the steps to reproduce?

import formidable from 'formidable';

export const config = {
  api: {
    bodyParser: false,
  },
};

export default async (req, res) => {
  const form = new formidable.IncomingForm();
  form.on('fileBegin', (name, file) => {
    file.path = "./" + file.name

  });
  form.parse(req, (err, fields, files) => {
    console.log(files);
  });

  res.end()
};

I’m trying to upload an image as form-data to a Nextjs api route. I use the package formidable to parse and save the file in a server folder. For the http request I use postman on the client.

What was the result you got?

The image (jpeg) is saved in the folder. However, it appears to be corrupt or damaged. Here is the corrupted image:

https://i.gyazo.com/1ce276c4968dc7e1cd24da74fe380467.png

What result did you expect?

Well, the original image. (https://i.gyazo.com/6ded28032d5dd5a0f02fd2a5052a57fc.png)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
tunnckoCorecommented, May 14, 2020

Thanks. Strange… These examples from this repo work?

Oooh, that’s serverless function above, right? Then try formidable-serverless until #594 if that’s the case.

1reaction
waigelcommented, May 14, 2020

Yes, this applies to all uploaded images.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The images on my website have been corrupted, what went ...
The images on my website have been corrupted, what went wrong? Print ... Sometimes this can occur as a result of uploading your...
Read more >
Corrupted Image Repair Guide to Recover Damaged Photos ...
Simply upload the corrupted images on the software and hit on the "Repair" function. Within minutes, your photos will be repaired.
Read more >
How do I solve Photo upload image corrupt…
As a test, try export the pics from iPhoto (File -> Export) and make sure they are good. If they are then upload...
Read more >
The uploaded image is corrupt and cannot be processed ...
The message "The uploaded image is corrupt and cannot be processed" is absolutely misleading. The image is OK, but your API just refuses...
Read more >
Image file is corrupted after uploading using servlet [duplicate]
You are not reading in the image data: InputStream is = req.getInputStream(); byte[] data = new byte[is.available()]; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found