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.
Related
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).
I've created a VueJS App for file uploading in which it will be my admin panel (For CMS) with NodeJS as back-end. Now I want to upload the files that was passed to the NodeJS and move it to another VueJS App which is going to be my primary website in order for me to access the files locally. How can I do it? Any suggestions or different approach will do.
You have many options on how to move the files to another site.
You could store them in a shared bucket or shared directory between your 2 backends or you could add another route to download that file.
You could configure a cronjob to scp or rsync those files to your target machine.
This is really more of a question of how to sync a directory to some place else.
When I am trying to do some changes to my node project and redeploying it to elastic beanstalk, I am losing the previous uploaded image but the text contents remains same. My application is uploading image when it is on the server side. But once I upload a new version my all uploaded files got missing.
Please note that I have also added MongoDB client with the EC2 instance IP.
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.
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.