项目作者: AndrewJBateman

项目描述 :
:clipboard: FCC project to be able to select and upload a file via a UI
高级语言: HTML
项目地址: git://github.com/AndrewJBateman/file-metadata.git
创建时间: 2018-06-01T07:50:40Z
项目社区:https://github.com/AndrewJBateman/file-metadata

开源协议:

下载


:zap: File Metadata Microservice for freeCodeCamp

  • extracts uploaded file metadata and stores file using multer node.js middleware
  • This was part of the FreeCodeCamp exercises for Front End Certification
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size
GitHub pull requests
GitHub Repo stars
GitHub last commit

:page_facing_up: Table of contents

:books: General info

  • Original instructions (User Stories) from FCC:
  1. I can submit a form that includes a file upload.
  2. The from file input field has the “name” attribute set to “upfile”. We rely on this in testing.
  3. When I submit something, I will receive the file name and size in bytes within the JSON response
  4. To handle the file uploading you should use the multer npm package.

:camera: Screenshots

Example screenshot.

:signal_strength: Technologies

  • Node v14 javaScript runtime built on Chrome’s V8 JavaScript engine
  • Express v5 Fast, unopinionated, minimalist web framework for Node.js
  • multer v1 node.js middleware for handling multipart/form-data, mainly used for uploading files
  • Cors v2 node.js package for providing Connect/Express middleware that can be used to enable CORS with various options.

:floppy_disk: Setup

  • Run node server.js for a dev server. Navigate to http://localhost:8080/.
  • The app will not automatically reload if you change any of the source files.

:computer: Code Examples

  • extract from server.js to upload file and produce a json object with file details (or error message if it does not work)
  1. app.post('/api/fileanalyse', upload.single('upfile'), (req, res, next) => {
  2. const fileSize = req.file && req.file.size;
  3. console.log(typeof fileSize); //should return 'number'
  4. res.json(
  5. typeof fileSize == 'undefined'
  6. ? { error: 'sorry, but there is a file error' }
  7. : {
  8. name: req.file.originalname,
  9. type: req.file.mimetype,
  10. size: req.file.size + ' bytes',
  11. }
  12. );
  13. });

:cool: Features

  • multer used to upload files - uploaded files stored in a folder named ‘uploads’. If this folder does not exist then it is created.

:clipboard: Status & To-Do List

  • Status: Working
  • To-Do: nothing

:clap: Inspiration

:file_folder: License

  • This project is licensed under the terms of the MIT license.

:envelope: Contact