1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- var path = require('path');
- var formidable = require('formidable');
- var fs = require('fs-extra');
- const uuidV1 = require('uuid/v1');
- exports.uploadImage = function(req, res){
-
- var form = new formidable.IncomingForm();
-
- form.multiples = false;
-
-
- form.on('file', function(field, file) {
- fileEndName = uuidV1() + file.name;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fs.copySync(file.path, path.join(uploadDir + fileEndName));
- fs.remove(file.path);
- });
-
- form.on('error', function(err) {
- console.log('An error has occured: \n' + err);
- });
-
- form.on('end', function() {
- res.end('/media/' + fileEndName);
- });
-
- form.parse(req);
- };
|