DEV Community

Cover image for React Image Upload with Preview example
Tien Nguyen
Tien Nguyen

Posted on • Edited on

3 2

React Image Upload with Preview example

In this tutorial, I will show you way to build React.js Image Upload example with Preview to a Rest API. The React App uses Axios and Multipart File for making HTTP requests, Bootstrap for progress bar. You also have a display list of images' information (with download url).

Full Article: https://bezkoder.com/react-image-upload-preview/

Overview

We’re gonna create a React Image upload application in that user can:

  • see the preview of image before uploading
  • see the upload process (percentage) with progress bar
  • view all uploaded images
  • link to download the image when clicking on the file name

react-image-upload-with-preview-example

Technology

  • React 16/17
  • Axios 0.21.1
  • Bootstrap 4

Rest API for File Upload & Storage

Here is the API that our React App will work with:

  • POST /upload: upload a File
  • GET /files: get List of Files (name & url)
  • GET /files/\[filename\]: download a File

You can find how to implement the Rest APIs Server at one of following posts:
- Node.js Express File Upload Rest API example
- Spring Boot Multipart File upload (to static folder) example
- Or: Spring Boot Multipart File upload (to database) example

React App for upload/download Image with preview

After building the React project is done, the folder structure will look like this:

react-image-upload-with-preview-example-project-structure

Let me explain it briefly.

  • file-upload.service provides methods to save File and get Files using Axios.
  • image-upload.component contains upload form, image preview, progress bar, display of list of images with download url.
  • App.js is the container that we embed all React components.
  • http-common.js initializes Axios with HTTP base Url and headers.
  • We configure port for our App in .env

For more details, implementation and Github, please visit:
https://bezkoder.com/react-image-upload-preview/

Further Reading

- React Multiple Files upload example with Progress Bar
- React.js CRUD example to consume Web API
- React JWT Authentication (without Redux) example
- React + Redux: JWT Authentication example

Neon image

Build better on Postgres with AI-Assisted Development Practices

Compare top AI coding tools like Cursor and Windsurf with Neon's database integration. Generate synthetic data and manage databases with natural language.

Read more →

Top comments (0)

Neon image

Next.js applications: Set up a Neon project in seconds

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay