Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Nodejitsu file system and static files

Nodejitsu file system and static files

Problem

When using Nodejitsu as hosting how can you store a few user uploads? I know the space is limited but my question is how can you backup those files saved when the file system is not persistent and every time I upload a newer version I lose them? What architecture is suggested for such usage? Do I need to create a static file server, use a cloud based solution like aws s3 or something else? I've tried downloading the tar for the current active version but any files created by users are not downloaded as well...

Problem courtesy of: anges244

Solution

I use nodejitsu and I use S3 to handle file uploads.

It's really easy to set it up.

Relevant post: NodeJS Request Upload Image

Code:

var fs = require ('fs')
fs.readFile(req.files.image.path, function (err, data) {

    var AWS = require('./aws_config')
    var s3 = new AWS.S3()
    var bucket =  ''
    s3.putObject({
      ACL: 'public-read', // by default private access
      Bucket: bucket,
      Key: file_name,
      Body: data
    }, function (err, data) {
      if (err) {
        console.log(err)
        res.send(500, {msg: 'image upload failed', error: err})
      } else {
        console.log('S3 upload Successful')

        res.send({})
      }
});
Solution courtesy of: tpae

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Nodejitsu file system and static files

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×