Activating the Backend
Begin by navigating to your image optimizer application directory and activating your virtual environment. After that, start your Flask application with the following commands:For testing purposes, you can use Postman to verify that your API is running correctly.
Connecting the React Application
Within your React app, update the API endpoint so that it correctly points to your Flask backend. Below is the core functionality for image uploading through React:Using Developer Tools
When testing your application, open your browser’s developer tools to monitor network activity and validate that the Flask server is accessible at127.0.0.1:5000. For instance, after choosing an image like “coolgirl.jpeg” from your computer, you should see a preview similar to the one below:

Handling CORS in Flask
When running the React app and Flask API on separate ports, you might experience CORS errors. To resolve this, install Flask-Cors in your virtual environment:__init__.py) to enable CORS:
This configuration allows requests solely from the defined origin. Update these settings as needed when deploying to production.
Displaying Optimized Images and File Size Comparison
A major feature of this project is the display of both the original and optimized images, including their file sizes, for side-by-side comparison. Once you click the “Optimize Image” button, the React component processes the binary response from the Flask endpoint and displays the optimized image with its size information. For example:
Final Steps and Deployment Considerations
Before finalizing the frontend integration, consider these additional improvements:- Store the API endpoint URL as an environment variable to enhance flexibility across different deployment environments.
- Add comprehensive inline documentation in the code.
- Prepare the repository for public release by following best practices on GitHub.
