diff --git a/Rev1/node/.gitignore b/Rev1/node/.gitignore index 6a7d6d8..0053508 100644 --- a/Rev1/node/.gitignore +++ b/Rev1/node/.gitignore @@ -127,4 +127,6 @@ dist .yarn/unplugged .yarn/build-state.yml .yarn/install-state.gz -.pnp.* \ No newline at end of file +.pnp.* + +public/upload/raw \ No newline at end of file diff --git a/Rev1/node/package-lock.json b/Rev1/node/package-lock.json index 66f35ec..dd5da3c 100644 --- a/Rev1/node/package-lock.json +++ b/Rev1/node/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "cors": "^2.8.5", "express": "^4.18.1", "express-fileupload": "^1.4.0", "fs": "^0.0.1-security", @@ -580,6 +581,18 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/crypto-random-string": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", @@ -2878,6 +2891,15 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "crypto-random-string": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", diff --git a/Rev1/node/package.json b/Rev1/node/package.json index 951c521..fd61eec 100644 --- a/Rev1/node/package.json +++ b/Rev1/node/package.json @@ -10,6 +10,7 @@ "author": "Selcuk Sari", "license": "ISC", "dependencies": { + "cors": "^2.8.5", "express": "^4.18.1", "express-fileupload": "^1.4.0", "fs": "^0.0.1-security", diff --git a/Rev1/node/public/js/signer.js b/Rev1/node/public/js/signer.js index 0a6ecaa..4148af0 100644 --- a/Rev1/node/public/js/signer.js +++ b/Rev1/node/public/js/signer.js @@ -20,6 +20,9 @@ function submitForm(e) { for (let i = 0; i < imgFiles.files.length; i++) { formData.append("files", imgFiles.files[i]); } + for (key in formData.keys()) { + console.log(key); + } fetch("http://localhost:3000/invoice_sign/upload_files", { method: "POST", body: formData, diff --git a/Rev1/node/routes/invoice_sign.js b/Rev1/node/routes/invoice_sign.js index 83d11c4..6eafdee 100644 --- a/Rev1/node/routes/invoice_sign.js +++ b/Rev1/node/routes/invoice_sign.js @@ -128,14 +128,25 @@ router.get("/download", function (req, res) { }); const multer = require("multer"); -const upload = multer({ dest: "./public/upload/raw" }); -// router.use(express.json()); -// router.use(express.urlencoded({ extended: true })); +const fileStorageEngine = multer.diskStorage({ + destination: (req, file, cb) => { + cb(null, "./public/upload/raw"); + }, + filename: (req, file, cb) => { + const fileName = decodeURI(file.originalname); + console.log(fileName); + cb(null, fileName); + }, +}); + +const upload = multer({ storage: fileStorageEngine }); router.post("/upload_files", upload.array("files"), uploadFiles); -function uploadFiles(req, res, next) { - console.log(req.body); - console.log(req.files); +function uploadFiles(req, res) { + // console.log(req.body); + // console.log(req.files); + // console.log(req.files[0].toString("latin1")); + res.setHeader("Access-Control-Allow-Origin", "*"); res.json({ message: "Successfully uploaded files" }); } diff --git a/Rev1/node/views/invoice_sign.pug b/Rev1/node/views/invoice_sign.pug index 1436390..343d24d 100644 --- a/Rev1/node/views/invoice_sign.pug +++ b/Rev1/node/views/invoice_sign.pug @@ -5,6 +5,8 @@ block content .row .col-sm-8 h3 Invoice Signer + .progress + .progress-bar.progress-bar-animated.progress-bar-striped(role="progressbar",aria-valuenow="30",aria-valuemin="0",aria-valuemax="100",style="width: 25%") form#form .m-3 label.form-label.file-upload-wrapper(for='formFile') Choose a file to embed an image