node.js - file upload on bluemix in nodejs -


i'm developing node.js bluemix application, offers api image/file upload, processes images mongodb service. locally, service works perfectly. unfortunately, service can't access uploaded files on bluemix? - how fix this? thank in advance

require('rootpath')(); var express = require('express'); var app = express(); var session = require('express-session'); var bodyparser = require('body-parser'); var expressjwt = require('express-jwt'); var config = require('config.json'); var cookieparser = require('cookie-parser'); var helmet = require('helmet'); var cors = require('cors'); var md5 = require('md5'); var sha1 = require('js-sha1'); var sha256 = require('js-sha256'); var crypto = require('crypto'); var path = require('path'); var multer = require('multer');  var mkdirp = require('mkdirp');     var storage = multer.diskstorage({      destination: function(req, file, cb) {         var dir = './uploads/' + req.query.projectid + '/' + req.query.milestoneid + '/';         mkdirp(dir, function(err) {             if (err) {                 console.error(err);             }             // move cb here             cb(null, dir);         });          console.log("upload: saved " + dir + file.originalname);     },     filename: function(req, file, cb) {         cb(null, file.originalname);     }  })    var upload = multer({ storage: storage })    var genrandomstring = function(length) {     return crypto.randombytes(math.ceil(length / 2))         .tostring('hex') /** convert hexadecimal format */         .slice(0, length); /** return required number of characters */ }; var sha512 = function(password, salt) {     var hash = crypto.createhmac('sha512', salt); /** hashing algorithm sha512 */     hash.update(password);     var value = hash.digest('hex');     return {         salt: salt,         passwordhash: value     }; };  function salthashpassword(userpassword) {     var salt = genrandomstring(16); /** gives salt of length 16 */     var passworddata = sha512(userpassword, salt);     console.log('userpassword = ' + userpassword);     console.log('passwordhash = ' + passworddata.passwordhash);     console.log('nsalt = ' + passworddata.salt); }  //salthashpassword('mypassword'); //salthashpassword('mypassword');  app.use(cors()); app.use(helmet()); app.use(cookieparser()); app.set('view engine', 'ejs'); app.set('views', __dirname + '/views'); app.use(bodyparser.urlencoded({ extended: false })); app.use(bodyparser.json()); app.use(session({ secret: config.secret, resave: false, saveuninitialized: true }));  // use jwt auth secure api app.use('/api', expressjwt({ secret: config.secret }).unless({ path: ['/api/users/authenticate', '/api/users/register'] }));  // routes  app.use('/api/fileuploads', require('./controllers/api/svr.fileupload.controller')); app.use('/api/session', require('./controllers/api/svr.session.controller')); app.use('/api/uploadimage', require('./controllers/api/svr.imageupload.controller'));   app.use('/js', express.static(__dirname + '/node_modules/bootstrap/dist/js')); // redirect bootstrap js app.use('/js', express.static(__dirname + '/node_modules/jquery/dist')); // redirect js jquery app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css')); // redirect css bootstrap app.use('/img', express.static(__dirname + '/views')); app.use('/img/project', express.static(__dirname + '/images')); app.use('/file/project', express.static(__dirname + '/files')); app.use('/uploaddoc', express.static(__dirname + '/uploads')); app.use('/uploadimage', express.static(__dirname + '/images'));   app.post('/savedata', upload.single('file'), function(req, res, next) {     console.log('upload successful req.file = ', req);     console.log('upload successful req.body = ', req.body);      var hash1 = md5(req.file);      console.log('md5=', hash1);     salthashpassword(hash1);      return res.send(hash1); });     // make '/app' default route app.get('/', function(req, res) {     return res.redirect('/app'); });  // start server var server = app.listen(process.env.port || 3000, function() {     console.log('server listening @ http://' + server.address().address + ':' + server.address().port); }); 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -