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.

Multer silent crash on uploading

See original GitHub issue

When trying to upload a file of 143KB I receive the following error:

Bad Gateway

The proxy server received an invalid response from an upstream server. Apache/2.4.10 (Debian) Server at 50.116.34.26 Port 80

When trying to upload a file of 4KB I receive one of the two, randomly:

Proxy Error

The proxy server received an invalid response from an upstream server. The proxy server could not handle the request POST /grimoireworks/admin/uploads/uploadimage.

Reason: Error reading from remote server

or

Service Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later. Apache/2.4.10 (Debian) Server at 50.116.34.26 Port 80

this is the code I’m using on the route:

app.post('/admin/uploads/uploadimage',
	ajaxAdminLoggedIn,
	upload.single('image_file'),
	function(req, res, next) {
		console.log("start of upload");

		req.socket.setTimeout(10000);

		var supportedTypes = ['image/jpeg', 'image/png', 'image/gif'];
		var type = req.file.mimetype;//mime.lookup(req.files.image_file.path);

		console.log("before supportedTypes check");

		if (supportedTypes.indexOf(type) == -1) {
			fs.unlink(req.file.path);
			return res.send(415, 'Supported image formats: jpeg, jpg, jpe, gif, png.');
		}

		console.log("before targetPath");

		var targetPath = __dirname + '/public/images/';
		if (req.body.image_type == "wizard") {
			targetPath += 'classes/';
		} else if (req.body.image_type == "spell") {
			targetPath += 'spells/';
		} else {
			fs.unlink(req.file.path);
			return res.send(415, 'Invalid image type.');
		}

		console.log("before tempPath");

		var tempPath = req.file.path;

		console.log("before createReadStream");

		var source = fs.createReadStream(tempPath);
		var dest = fs.createWriteStream(targetPath + req.file.originalname);

		console.log(tempPath);
		console.log(targetPath + req.file.originalname);

		source.pipe(dest);

		console.log("after pipe");

		source.on('error', function(err) {
			if (err) {
				return res.send(500, 'Something went wrong');
			}
		});

		source.on('end', function() {
			//delete file from temp folder
			fs.unlink(tempPath, function(err) {
				if (err) {
					return res.send(500, 'Something went wrong');
				}

				res.redirect('back');
			}); //#end - unlink
		}); //#end - on.end
	}
);

This is the form

<form action="<%= relativePath %>/admin/uploads/uploadimage" method="post" enctype="multipart/form-data">
							<div class="form-group">
								<p>Select the type of the image:</p>
								<label>
									<input type="radio" name="image_type" id="image_type_wizard" value="wizard" checked>
									Wizard
								</label>
								<br>
								<label>
									<input type="radio" name="image_type" id="image_type_spell" value="spell">
									Spell
								</label>
							</div>
							<div class="form-group">
								<label for="image_file">Select your image:</label>
								<input type="file" name="image_file" id="image_file" />
								<p class="help-block">Supported files: jpg, jpeg, gif, png.</p>
							</div>
							<div class="text-right">
								<button type="submit" class="btn btn-success">Submit</button>
							</div>
						</form>

Besides this multer is just using this:

var bodyParser = require( 'body-parser' );
var multer  = require('multer');

No logs appear anywhere, the node application restarts when trying to upload a file.

Apache just shows:

[Sun Apr 16 22:40:11.299511 2017] [proxy_http:error] [pid 29899] (20014)Internal error: [client 189.35.245.253:7512] AH01102: error reading status line from remote server 127.0.0.1:6161, referer: http://50.116.34.26/grimoireworks/admin/uploads [Sun Apr 16 22:40:11.527747 2017] [proxy:error] [pid 29900] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:6161 (127.0.0.1) failed [Sun Apr 16 22:40:11.527800 2017] [proxy:error] [pid 29900] AH00959: ap_proxy_connect_backend disabling worker for (127.0.0.1) for 60s [Sun Apr 16 22:40:11.527806 2017] [proxy_http:error] [pid 29900] [client 189.35.245.253:7519] AH01114: HTTP: failed to make connection to backend: 127.0.0.1, referer: http://50.116.34.26/grimoireworks/admin/uploads

Issue Analytics

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

github_iconTop GitHub Comments

46reactions
iLyxa3Dcommented, Oct 25, 2017

For the record, turns out, there was no crash 😃 PM2 watched the changes in the folder and rebuild the application automatically - looks like crash restarting without error log. Excluding the download folder from the list of the watch (pm2 … --ignore-watch “folder_name”) stoped restarting.

4reactions
ayanthcommented, Dec 8, 2017

@iLyxa3D Thank you so much! Been digging around to resolve this issue for a while. So many technologies… so many different possiblities.

But in the end it was all from watch.

Thank you again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

File upload keeps crashing for larger files - NodeJS
var storage = multer({storage: storage, limits: {fileSize: 10MB, fieldSize: 10MB}}).diskStorage({ destination: function(req, file, cb) { .
Read more >
Upload Files to Next.js With API Routes | by Robert S (codeBelt)
A brief overview how to upload files with React and Next.js API Routes. How to use React, Next-Connect, Multer and Axios to upload...
Read more >
Chapter 15. Releasing and updating applications - Electron in ...
Sending crash reports from Electron; Sending reports of uncaught exceptions from Electron; ... 'crashes'); const upload = multer({ #3 dest: crashesPath, }) ...
Read more >
Fix "Unexpected field" Error From Multer - Maxim Orlov
You set out to implement file uploads in Node.js, only to get blocked by this particular error: MulterError: Unexpected field.
Read more >
[Solved]-Multer returns req.file as undefined, and req.file ...
Firstly, if you want to upload files to s3 and not store it on your server, you can store the uploaded file as...
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