Nodejitsu file system and static files

452 views Asked by At

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...

1

There are 1 answers

1
tpae On BEST ANSWER

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({})
      }
});