Skip to content

Instantly share code, notes, and snippets.

@romelgomez
Last active December 15, 2015 02:30
Show Gist options
  • Save romelgomez/55d4f6f99a1162c2314e to your computer and use it in GitHub Desktop.
Save romelgomez/55d4f6f99a1162c2314e to your computer and use it in GitHub Desktop.
(Solved) How get the form data. Express 5.0.0-alpha.2
Where i use $upload service
var uploadFile = function(file,fileId){
var deferred = $q.defer();
file.upload = $upload.upload({
url: "/files",
fields: {
public_id: 'publications/'+fileId,
upload_preset: 'ebdyaimw',
context: 'alt=' + file.name + '|caption=' + file.name + '|photo=' + file.name + '|$id=' + fileId
},
file: file
}).progress(function (e) {
file.progress = Math.round((e.loaded * 100.0) / e.total);
//file.status = "Uploading... " + file.progress + "%";
}).success(function (data) {
//$log.info('success - data - to json',angular.toJson(data));
file.inServer = true;
file.$id = data.context.custom.$id;
deferred.resolve({
'$id':data.context.custom.$id
});
}).error(function (data) {
file.details = data;
deferred.reject();
});
return deferred.promise;
};
#### server.js NODE
#############################
// set up ========================
var express = require('express');
var app = express(); // create our app w/ express
var morgan = require('morgan'); // log requests to the console (express4)
var path = require('path'); // normalize the paths : http://stackoverflow.com/questions/9756567/do-you-need-to-use-path-join-in-node-js
var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)
var port = process.env.PORT || 8080;
// configuration =================
app.use(express.static(path.join(__dirname, 'public'))); // set the static files location /public/img will be /img for users
app.use('/bower_components', express.static(path.join(__dirname, 'bower_components'))); // set the static files location of bower_components
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());
require('./app/routes')(app);
require('./app/cloudinaryAPI')(app);
require('./app/algoliasearch');
var server = app.listen(port, function(){
console.log('The server is running in port localhost: ',port);
});
##### cloudinaryAPI.js NODE
############################
var formidable = require('formidable');
var cloudinary = require('cloudinary');
cloudinary.config({
cloud_name: '******',
api_key: '****************',
api_secret: '***********************'
});
function $upload(req, res){
}
function $delete(publicIDList){
//cloudinary.api.delete_resources(publicIDList,
// function(result){
//
// });
}
module.exports = function(app){
app.post('/files', function(req, res){
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
console.log('File name', files.file.name);
console.log('Fields', fields);
});
});
app.delete('/files',function(req, res){
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment