Corrupt image when uploading
See original GitHub issueSupport 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:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.Yes, this applies to all uploaded images.