Multer silent crash on uploading
See original GitHub issueWhen 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:
- Created 6 years ago
- Reactions:3
- Comments:10 (1 by maintainers)
Top GitHub Comments
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.
@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!