GithubHelp home page GithubHelp logo

andrewjbateman / fullstack-react-node-fileupload Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 13.67 MB

:clipboard: App with a React frontend and node/express backend. Uploads image files from frontend UI to backend

JavaScript 78.83% CSS 7.18% HTML 13.99%
fullstackreact reactjs nodejs expressjs html5 css3 file-upload tutorial-code

fullstack-react-node-fileupload's Introduction

React File Upload

Express backend server app to handle file uploads. React frontend.

*** Note: to open web links in a new window use: ctrl+click on link**

Table of contents

General info

  • Uploads an image file from the React frontend. This file is fetched by the backend using express.jsm and stored in a files directory in the public folder.

  • The frontend uses a FormData object with inputs for the file itself and a file name. The image will be displayed on the frontend.

Screenshots

Example screenshot.

Technologies

Frontend Setup

npm run start

  • Runs the app in development mode. Open http://localhost:3000 to view in browser.

  • The page will reload if you make edits. You will also see any lint errors in the console.

Backend Setup

nodemon app.js

Code Examples

  • extract of Frontend Main.js that handles the file upload.
  // function to upload an image. FormData() constructor used to create a new FormData object.  
  // file will be fetched by the backend server running on port 8000.
  handleUploadImage(event) {
    event.preventDefault();

    const data = new FormData();
    data.append('file', this.uploadInput.files[0]);
    data.append('filename', this.fileName.value);

    fetch('http://localhost:8000/upload', {
      method: 'POST',
      body: data,
    }).then((response) => {
      response.json().then((body) => {
        this.setState({ imageURL: `http://localhost:8000/${body.file}` });
      });
    });
  }

Status & To-Do List

  • Status: updated oct 2019. working front-end. When running back-end gives a 404 error message 'file not found'.

  • To do: check backend code.

Inspiration

Contact

Repo created by ABateman - feel free to contact me!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.