Last active
March 10, 2020 09:04
Revisions
-
tkh44 revised this gist
Jan 3, 2014 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ <form id="uploadForm" enctype="multipart/form-data" action="/upload/upload" method="post"> <input type="file" id="userPhotoInput" name="userPhoto" /> </form> -
tkh44 renamed this gist
Jan 2, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
tkh44 renamed this gist
Jan 2, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
tkh44 revised this gist
Jan 2, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,8 @@ function fileExtension(fileName) { return fileName.split('.').slice(-1); } // Where you would do your processing, etc // Stubbed out for now function processImage(id, name, path, cb) { console.log('Processing image'); -
tkh44 revised this gist
Jan 2, 2014 . 3 changed files with 23 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ module.exports = { get: function (req, res) { res.sendfile(req.path.substr(1)); }, _config: { rest: false, shortcuts: false } }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,8 @@ var fs = require('fs'); var mkdirp = require('mkdirp'); //var io = require('socket.io'); var UPLOAD_PATH = 'public/images'; // Setup id generator sid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@'); sid.seed(42); @@ -42,8 +44,7 @@ module.exports = { var file = req.files.userPhoto, id = sid.generate(), fileName = id + "." + fileExtension(safeFilename(file.name)), dirPath = UPLOAD_PATH + '/' + id, filePath = dirPath + '/' + fileName; try { @@ -76,8 +77,5 @@ module.exports = { * Overrides for the settings in `config/controllers.js` * (specific to GifController) */ _config: {} }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ module.exports.routes = { '/': { view: 'home/index' }, 'get /public/images/*': { controller: 'FileController', action: 'get' } }; -
tkh44 revised this gist
Jan 2, 2014 . 2 changed files with 10 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,5 +76,8 @@ module.exports = { * Overrides for the settings in `config/controllers.js` * (specific to GifController) */ _config: { rest: false, shortcuts: false } }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,9 @@ Setup ----- cd /your/project/dir sails generate controller upload upload sails generate file get npm install shortid mkdirp -D -
tkh44 revised this gist
Jan 2, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ Setup ----- npm install shortid mkdirp -D -
tkh44 revised this gist
Jan 2, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ setup ----- npm install shortid mkdirp -D -
tkh44 revised this gist
Jan 2, 2014 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ setup ----- npm install shortid mkdirp -D -
tkh44 revised this gist
Jan 2, 2014 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ var sid = require('shortid'); var fs = require('fs'); var mkdirp = require('mkdirp'); //var io = require('socket.io'); -
tkh44 revised this gist
Jan 2, 2014 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ var sid = require('shortid'); var fs = require('fs'); var path = require('path'); -
tkh44 created this gist
Jan 2, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,84 @@ var sid = require('shortid'); var _ = require('underscore'); _.str = require('underscore.string'); var fs = require('fs'); var path = require('path'); var mkdirp = require('mkdirp'); //var io = require('socket.io'); // Setup id generator sid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@'); sid.seed(42); function safeFilename(name) { name = name.replace(/ /g, '-'); name = name.replace(/[^A-Za-z0-9-_\.]/g, ''); name = name.replace(/\.+/g, '.'); name = name.replace(/-+/g, '-'); name = name.replace(/_+/g, '_'); return name; } function fileMinusExt(fileName) { return fileName.split('.').slice(0, -1).join('.'); } function fileExtension(fileName) { return fileName.split('.').slice(-1); } function processImage(id, name, path, cb) { console.log('Processing image'); cb(null, { 'result': 'success', 'id': id, 'name': name, 'path': path }); } module.exports = { upload: function (req, res) { var file = req.files.userPhoto, id = sid.generate(), fileName = id + "." + fileExtension(safeFilename(file.name)), size = parseInt(req.headers['content-length'], 10), dirPath = 'public/gifs/' + id, filePath = dirPath + '/' + fileName; try { mkdirp.sync(dirPath, 0755); } catch (e) { console.log(e); } fs.readFile(file.path, function (err, data) { if (err) { res.json({'error': 'could not read file'}); } else { fs.writeFile(filePath, data, function (err) { if (err) { res.json({'error': 'could not write file to storage'}); } else { processImage(id, fileName, filePath, function (err, data) { if (err) { res.json(err); } else { res.json(data); } }); } }) } }); }, /** * Overrides for the settings in `config/controllers.js` * (specific to GifController) */ _config: {} };