├── _config.yml ├── package.json ├── README.md ├── server.js ├── public └── style.css ├── LICENSE └── views └── index.html /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "file_metadata", 3 | "version": "0.0.1", 4 | "description": "API project for freeCodeCamp", 5 | "main": "server.js", 6 | "scripts": { 7 | "start": "node server.js" 8 | }, 9 | "dependencies": { 10 | "express": "^5.0.0-alpha.2", 11 | "cors": "^2.8.1", 12 | "multer": "^1.3.1" 13 | }, 14 | "engines": { 15 | "node": "4.4.5" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "https://hyperdev.com/#!/project/welcome-project" 20 | }, 21 | "keywords": [ 22 | "node", 23 | "hyperdev", 24 | "express" 25 | ], 26 | "license": "MIT" 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # API Project: File Metadata Microservice for freeCodeCamp 2 | 3 | ### User stories: 4 | 5 | 1. I can submit a form that includes a file upload. 6 | 2. The from file input field has the "name" attribute set to "upfile". We rely on this in testing. 7 | 3. When I submit something, I will receive the file name and size in bytes within the JSON response 8 | 9 | ### Usage : 10 | 11 | - Go to the main page, and upload a file using the provided form. 12 | 13 | ### Hint: 14 | 15 | - To handle the file uploading you should use the [multer](https://www.npmjs.com/package/multer) npm package. 16 | 17 | Solution is hosted on glitch, 18 | 19 | - https://curved-voice.glitch.me 20 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var express = require("express"); 4 | var cors = require("cors"); 5 | var multer = require("multer"); 6 | // require and use "multer"... 7 | 8 | var app = express(); 9 | 10 | app.use(cors()); 11 | app.use("/public", express.static(process.cwd() + "/public")); 12 | 13 | app.get("/", function(req, res) { 14 | res.sendFile(process.cwd() + "/views/index.html"); 15 | }); 16 | 17 | var upload = multer({ dest: "uploads/" }); 18 | app.post("/api/fileanalyse", upload.single("upfile"), function(req, res, next) { 19 | var upfile = req.file; 20 | if (typeof upfile === "undefined") res.json({ error: "file not uploaded" }); 21 | return res.json({ 22 | name: upfile.originalname, 23 | type: upfile.mimetype, 24 | size: upfile.size 25 | }); 26 | }); 27 | 28 | app.listen(process.env.PORT || 3000, function() { 29 | console.log("Node.js listening ..."); 30 | }); 31 | -------------------------------------------------------------------------------- /public/style.css: -------------------------------------------------------------------------------- 1 | /****** Main Styling ******/ 2 | 3 | body { 4 | font-family: "Roboto", sans-serif; 5 | font-size: 16px; 6 | color: #222; 7 | background-color: #ecf0f1; 8 | text-align: center; 9 | } 10 | 11 | .container { 12 | padding: 0; 13 | margin-top: 40px; 14 | } 15 | 16 | .footer { 17 | margin-top: 60px; 18 | } 19 | 20 | ol { 21 | list-style-position: inside; 22 | } 23 | ul { 24 | list-style-type: none; 25 | } 26 | 27 | a { 28 | color: #2574a9; 29 | } 30 | 31 | input { 32 | display: block; 33 | position: relative; 34 | margin: 10px auto; 35 | } 36 | input#button { 37 | width: 230px; 38 | } 39 | .view { 40 | position: relative; 41 | margin: auto; 42 | margin-top: 40px; 43 | border: 1px solid #aaa; 44 | padding: 20px; 45 | width: 60%; 46 | min-width: 400px; 47 | } 48 | /****** Logo Div Styling ******/ 49 | 50 | img { 51 | margin: 20px auto 0 auto; 52 | display: block; 53 | } 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Dhanraj Acharya 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 |26 | Please Upload a File ... 27 |
28 |