123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //© 2019 Dublin City University, Trinity College Dublin. All rights reserved. This material may not be reproduced, displayed, modified or distributed without the express prior written permission of the copyright holder.
- import multer from 'multer';
- import path from 'path';
- const destination = __dirname+'/upload/';
- //const destination = path.normalize(path.resolve(__dirname))+'/upload/';
- let storage = multer.diskStorage({
- destination: function (req, file, callback) {
- callback(null, destination);
- },
- filename: function (req, file, callback) {
- let timeStamp = Date.now();
- let fileExtenstion =path.extname(file.originalname);
- let fileBaseName = path.basename(file.originalname, path.extname(file.originalname));
- callback(null, fileBaseName+'-'+timeStamp+fileExtenstion);
- }
- });
-
- let upload = multer({ storage : storage}).any();
- class fileUploadsController {
-
- upload(req, res) {
- upload(req,res,function(err) {
- if(err) {
- return res.status(404).send({
- message: 'File Upload Failed.'
- });
- }
- else
- {
- return res.status(200).send({
-
- message: 'File Upload Successful.',
- fileName: req.files[0].filename,
- filePath : destination
-
- });
- }
-
- });
- }
-
-
-
- }
- const fileUploadController = new fileUploadsController();
- export default fileUploadController;
|