Question

I can't upload files from html form on my node/express app

Hello,

I’m just running a simple Node.js/Express application on a droplet and I can’t upload files to the designated folder from a html form on a page of the application.

I’m just running the application with ‘node app.js’ and it runs on port 3000. I could be wrong but I don’t think Apache is involved here, is that correct?

I’ve chmod 777’d the folder to where the files go but every time I try and upload a file the application hangs for a few seconds and then gets “Killed”.

The upload location is ‘app_root/public/uploads’

I am aware of the security issues here, I just want to do a little bit of live testing, I don’t plan to the have the application up for long.

Thanks for any help! Jonathan


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Ok, It’s actually Jimp that is cause the problem here. I was trying to resize the file before saving, and it’s failing somewhere here:

function savePhoto(photo, userId) {
    var timestamp = Math.round((new Date()).getTime() / 1000);
    var photoname = userId + - + timestamp + '.png';
    jimp.read(photo.data, function (err, photo) {
        if (err) throw err;
        photo.resize(400, jimp.AUTO)            
            .quality(70)
            .write("public/uploads/" + photoname);
    });
    return photoname;
}

whereas if i use ‘express-fileupload’ to save the file, it works fine:

function savePhoto(photo, userId) {
    var timestamp = Math.round((new Date()).getTime() / 1000);
    var photoname = userId + - + timestamp + '.png';
    photo.mv('public/uploads/' + photoname, function(err) {
        if (err) throw err;
    });
    return photoname;
}

Thanks for any help!

i dont know about your issue but i can tell if if specify the full path in the like root/app/public_uploads then you can easy the access , and this is give multer or other module to access the directory .which is possible from the local host

Actually you may need to set up a reverse proxy like nginx which directs all the requests to your node app.

Check this link out. https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04#set-up-nginx-as-a-reverse-proxy-server

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel