Uploaded Image Disappeard When Heroku Server Restart - node.js

I am using node.js to upload files to my Heroku server. Everything works fine, but when the Heroku server restarts or goes down all the uploaded files disappears, the URL hits returns 'Not Found'.

Experienced this months ago. You need to host the images somewhere else as Heroku does not support storing files in them. Ended up using Cloudinary to store files, and then later on getting a VPS server.

Media files and other user content that is uploaded by users should not be stored on Heroku. Heroku was built to run the application code and it only cares about the files of your application that are in your repository.
Heroku discards your previous environment on every deploy, and launches a new one based on your code repository.
So only application code should stay there, other things should be delegated to other services, in this case for file storage you should use something like S3 or similar.

Heroku has something called Ephemeral filesystem.
From the documentation:
Each dyno gets its own ephemeral filesystem, with a fresh copy of the
most recently deployed code. During the dyno’s lifetime its running
processes can use the filesystem as a temporary scratchpad, but no
files that are written are visible to processes in any other dyno and
any files written will be discarded the moment the dyno is stopped or
restarted.

Related

How to download heroku running file?

Is there any possibility to download running app file?
Im using quick.db for my discord bot database and I need that running json database file with user data before restarting. When I will deploy a new build, then the old json database file from github will load and I will lose all new data in that database.
Thx for anything...
You can programmatically upload the json file to remote storage (S3, DropBox): you can do this at restart (if you can intercept the event) or at regular times (this might not work for you, it depends how often the db is updated).
You can read about some possible options on Heroku Files
The download option is not a good idea because you need to secure the download endpoint (I believe you don't want anybody be able to grab your data) and also because the Dyno restarts at least every 24hrs (if you don't deploy for a day the Dyno will restart without notice and giving the time to download your data).

how to save uploaded file on elastic beanstalk?

I use a elastic-beanstalk service on AWS by using Node.js.
I use a multer for file upload and uploaded file is saved on webserver.
But when I publish a new version of project file, the files that saved on my webserver are gone.
I want to maintain the file on webserver.
just overwrite not rewrite.
so how can I solve this issue?
Thanks for your time!
When working with Elastic Beanstalk (or any auto-scaling environment), ideally you don't want to store anything on the server itself. If a user is uploading a file, save it somewhere off the server.
In AWS, this typically means storing it in S3 - this means that the file doesn't get lost when the project is updated or the server gets terminated.

Save image file to IBM Bluemix Node.js application

I have a Node.js application on IBM Bluemix.
I need to let the user upload a image. In my localhost, the image is save into the folder, no problems...
But when I do the same in production, the file isn't save to the server corresponding folder...
Someone can help?
Assuming this is a Cloud Foundry app ... the file system is ephemeral, you need to save the images somewhere external to the app for them to be persisted through app restarts.
There is a sample app that shows how to do this using Cloudant - https://github.com/IBM-Bluemix/nodejs-cloudant
You will need to specify the directory using __dirname , but every time you redeploy your application you will lose the files. Stoping and Restarting should be ok.

heroku retain files/folders while re-deploying new version of nodejs application to heroku

My folder structure for images looks like below
./public/img/**
under img folder I have following folders - categoryImages, languageImages, socialShareImages and userImages.
Now I want to retain the userImages as this contains images uploaded by user, But every time I deploy a new version of my app to heroku with "git push heroku master" it overwrites userImages folder.
I tried without userImages folder in my git repository but even this doesnt help. Looks like everytime you upload a new version of app every folder and file is rewritten. Now question is how can I retain this userImages folder?
Regards,
Chidan
Heroku has a ephemeral filesystem and as far as I know, (and as much as I wish it weren't) I don't think you can get any files to persist.
However, heroku offers a free Postgres database per app, and anything in your database will persist. You'll have to use the node.js pg package to access Postgres.
Edit: I believe it's also possible to use S3 (which might work better for something like images). You'll have to look that up though.

Deployed version of NodeJS site not loading on AWS

I am doing my first deployment on AWS (using Elastic Beanstalk), and I am completely new to this.
I built a personal website using NodeJS / Express, and on my local machine it loads just fine. Once I was ready to deploy a v1, I created an AWS account and set up a new EBS application environment for Node. I set up the static files to load from /public, set my node version, and set the launch command as node app.js, but those were the only options I changed.
I zipped up my site (using CNTL + Click -> Compress on a selection of all site files) and uploaded that zip, and after some time, it came up all green. Clicking the link to load my site though, I get a half finished version. Looking at my console, I see that I am getting 4 files as 404, and because of that, 4 failures from RequireJS.
These 4 files are backbone views, and are contained in a folder with 4 other JS files that are all loading just fine (I can open them in the chrome dev tools source tab from the deployed version). I am confused how just these 4 files would go missing.
Is there some way to FTP into where ever my files are contained, to confirm the files are in fact not present? And barring that, what steps are available to figure out what is occurring here? Like I said, it looks and loads just fine locally, and I am at a loss as to where to even start debugging something like this. The AWS docs I have read so far only tell me to do exactly what I have been doing.
Repo for the project is here: https://github.com/RyanMG/trustycode
And the deployment is here: http://trustycode.elasticbeanstalk.com/
The files it is having trouble with are under public/javascript/views/ (CodeView, AboutView, PhotoView, DesignView)
Any ideas / advice?
Is there some way to FTP into where ever my files are contained, to confirm the files are in fact not present?
You can ssh into the EC2 instance of the Elastic Beanstalk app using your pem file.
Check files in /var/app/current
I don't have the reputation to comment, but that is one of those common gotchas I found myself switching to OSX from GNU/LINUX at work. OSX is case insensitive; linux world is case sensitive.

Resources