Getting "Empty file" error when file is full?
I'm trying to upload image files to cloudinary from react frontend and node backend, and it works, but only for the first upload. After that it gives me "Empty file" error, even though when I log the files from the incoming req object and it shows the file is present. If I restart the server, again the first upload works, but every attempt after receives "Empty file" error.
Here is the current code in node server:
When I upload the first image, the node server console.logs this (the req.files):
-
Hi Thomas,
May I please check, are you logging the details (in particular, the size) of the file on the server before sending it to our SDK?
I don't just mean the value of 'file.tempFilePath' or 'files' but can you also check if the file exists on the disk and is non-empty?
Most likely, the error means that what was sent to our server was an empty file, but I can't see where in your code that could be happening. Is it possible the 'files' are being duplicated somehow, and the second request is sending two files in req.files, causing req.files.image to be empty, or something like that?
-
Hi Matt,
May I please ask for some more information about the exact calls you're making and any debugging steps you've taken?
If you have a small standalone project that demonstrates the issue that would be perfect, but some info I can use to create the same setup would be helpful, too.Thanks,
Stephen
-
Hi Stephen,
Thanks for your response. My code is very similar to Thomas's but I can post it later today. I think we're following the same examples, though.
I don't have a standalone project, but I do a simple function responsible for the upload and I know the exact line I get the error on if that helps. I also know how to recreate the bug, much as Thomas describes above. I just don't know why the problem is occurring. -
Hi Matt - Thanks, the full example would be helpful, or if you're working from a tutorial or other sample, a link to that
Thomas' example doesn't look like one of the sample apps distributed with our SDK, so I'm not sure how best to try and reproduce what's happening here - The upload() method in our SDK should be fine, and the most likely reason for an empty file error is that an empty file was passed to it, but I can't see why that might be in Thomas' example
-
Hi guys - I'm a bit late to the party, but thought I'd share what I learned. I was getting the same error as Thomas. I discovered that the issue is with `express-fileupload` and not with Cloudinary's `cloudinary.uploader.upload` function. I substituted `express-fileupload` with `multer` as per this blog https://code.tutsplus.com/tutorials/file-upload-with-multer-in-node--cms-32088 and I can no longer reproduce the error.
I hope it helps
Happy coding
Post is closed for comments.
Comments
7 comments