├── backend ├── .gitignore ├── upload │ ├── 1676385580200logo512.png │ ├── 1676385712949logo192.png │ ├── 1676386021736logo192.png │ ├── 1676386052365logo192.png │ ├── 1676386113172logo192.png │ ├── 1676386159351logo192.png │ └── 1676386188979logo192.png ├── routes │ └── images.js ├── server.js ├── package.json ├── controllers │ └── imagesController.js └── middleware │ └── filesMiddleware.js ├── frontend ├── public │ ├── robots.txt │ ├── manifest.json │ └── index.html ├── postcss.config.js ├── src │ ├── index.css │ ├── app.css │ ├── index.js │ ├── components │ │ ├── Pending.js │ │ ├── Uploaded.js │ │ └── Form.js │ ├── App.js │ └── assets │ │ └── image.svg ├── .gitignore ├── tailwind.config.js ├── package.json └── README.md └── README.md /backend/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /backend/upload/1676385580200logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahimKen/IMAGE-UPLOADER/HEAD/backend/upload/1676385580200logo512.png -------------------------------------------------------------------------------- /backend/upload/1676385712949logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahimKen/IMAGE-UPLOADER/HEAD/backend/upload/1676385712949logo192.png -------------------------------------------------------------------------------- /backend/upload/1676386021736logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahimKen/IMAGE-UPLOADER/HEAD/backend/upload/1676386021736logo192.png -------------------------------------------------------------------------------- /backend/upload/1676386052365logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahimKen/IMAGE-UPLOADER/HEAD/backend/upload/1676386052365logo192.png -------------------------------------------------------------------------------- /backend/upload/1676386113172logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahimKen/IMAGE-UPLOADER/HEAD/backend/upload/1676386113172logo192.png -------------------------------------------------------------------------------- /backend/upload/1676386159351logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahimKen/IMAGE-UPLOADER/HEAD/backend/upload/1676386159351logo192.png -------------------------------------------------------------------------------- /backend/upload/1676386188979logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahimKen/IMAGE-UPLOADER/HEAD/backend/upload/1676386188979logo192.png -------------------------------------------------------------------------------- /frontend/src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | *{ 6 | padding: 0; 7 | margin: 0; 8 | box-sizing: border-box; 9 | } 10 | -------------------------------------------------------------------------------- /frontend/src/app.css: -------------------------------------------------------------------------------- 1 | @keyframes loader { 2 | 0% {width: 0} 3 | 100% {width: 100%;} 4 | } 5 | 6 | .loader { 7 | animation-name: loader; 8 | animation-duration: 1s; 9 | animation-iteration-count: infinite; 10 | animation-direction: alternate; 11 | } -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | const root = ReactDOM.createRoot(document.getElementById('root')); 7 | root.render( 8 | 9 | 10 | 11 | ); 12 | 13 | 14 | -------------------------------------------------------------------------------- /backend/routes/images.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const { getImage , uploadImage } = require('../controllers/imagesController') 3 | const upload = require('../middleware/filesMiddleware') 4 | const router = express.Router() 5 | 6 | 7 | router.get('/download/:id' , getImage) 8 | router.post('/upload' , upload.single('image') , uploadImage) 9 | 10 | module.exports = router ; -------------------------------------------------------------------------------- /frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /backend/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const Imagerouter = require('./routes/images') 3 | const cors = require('cors') 4 | const app = express() 5 | 6 | //middlewares 7 | app.use(cors()) 8 | app.use(express.static('upload')); 9 | 10 | //routes 11 | app.use('/' , Imagerouter) 12 | 13 | const port = 5000 || process.env.PORT 14 | module.export = {port}; 15 | 16 | 17 | app.listen(port , () => console.log('app listening on port ' , port)) 18 | module.exports = port; 19 | 20 | -------------------------------------------------------------------------------- /frontend/src/components/Pending.js: -------------------------------------------------------------------------------- 1 | import '../app.css' 2 | const Pending = () => { 3 | return ( 4 |
5 |

Uploading...

6 |
7 |
8 |
9 |
10 | ) 11 | } 12 | 13 | export default Pending 14 | -------------------------------------------------------------------------------- /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "body-parser": "^1.20.1", 4 | "cors": "^2.8.5", 5 | "dotenv": "^16.0.3", 6 | "express": "^4.18.2", 7 | "express-fileupload": "^1.4.0", 8 | "mongoose": "^6.7.2", 9 | "multer": "^1.4.5-lts.1", 10 | "nodemon": "^2.0.20", 11 | "path": "^0.12.7" 12 | }, 13 | "scripts": { 14 | "start": "nodemon server.js" 15 | }, 16 | "name": "backend", 17 | "version": "1.0.0", 18 | "main": "server.js", 19 | "author": "", 20 | "license": "ISC", 21 | "description": "" 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Project Title 3 | 4 | Image Uploader App using React js - Tailwindcss - Node js - Express js 5 | 6 | 7 | ## How to Run it 8 | Firstly you need to open two Terminals in order to run the frontend and the backend in the same time . 9 | 10 | #### run the frontend 11 | 12 | ```bash 13 | cd frontend 14 | npm install 15 | npm run start 16 | ``` 17 | 18 | #### run the backend 19 | 20 | ```bash 21 | cd backend 22 | npm install 23 | npm run start 24 | 25 | ``` 26 | 27 | 28 | 29 | 30 | ## Screenshots 31 | ![App Screenshot](https://www.linkpicture.com/q/Capture-d-ecran_20230214_160652.png) 32 | 33 | ![App Screenshot](https://www.linkpicture.com/q/Capture-d-ecran_20230214_160858.png) 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /backend/controllers/imagesController.js: -------------------------------------------------------------------------------- 1 | const {port} = require('../server') 2 | const path = require('path') 3 | 4 | 5 | const getImage = async (req , res) => { 6 | const { id } = req.params; 7 | try{ 8 | res.sendFile(path.join(__dirname , '../upload' , id)) 9 | }catch(err){ 10 | res.status(400).json("server error can't retrieve image") 11 | } 12 | } 13 | 14 | const uploadImage = (req , res) => { 15 | const path = String(req.file.filename) 16 | try{ 17 | res.status(200).json({ 18 | path : `http://localhost:5000/download/${path}` 19 | }) 20 | 21 | } 22 | catch(error){ 23 | res.status(400).json(error) 24 | } 25 | } 26 | 27 | module.exports = {getImage , uploadImage} -------------------------------------------------------------------------------- /frontend/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | "./src/**/*.{js,jsx}" 5 | ], 6 | theme: { 7 | extend:{ 8 | colors : { 9 | 'blue' : '#2f80ed', 10 | 'green' : '#219653', 11 | 'grey' : '#fafafb' , 12 | 'light-grey' : '#f6f8fb', 13 | 'light-blue' : '#97bef4' 14 | }, 15 | keyframes : { 16 | loader : { 17 | '0%' : {width: '0'}, 18 | '25%' : {width: '25%'}, 19 | '50%' : {width: '50%'}, 20 | '75%' : {width: '75%'}, 21 | '100%' : {width: '100%'} 22 | } 23 | }, 24 | animation : { 25 | 'loaders' : 'loader 2s ease-in-out infinite' 26 | } 27 | } 28 | }, 29 | plugins: [], 30 | } -------------------------------------------------------------------------------- /backend/middleware/filesMiddleware.js: -------------------------------------------------------------------------------- 1 | const multer = require('multer') 2 | const path = require('path') 3 | 4 | const storage = multer.diskStorage({ 5 | destination : (req , file , cb) => { 6 | cb(null , 'upload') 7 | } , 8 | filename : (req , file , cb) => { 9 | const prefix = Date.now() + file.originalname 10 | cb(null , prefix) 11 | } 12 | }) 13 | 14 | 15 | const fileFilter = (req , file , cb) => { 16 | const allowedMimetypes = ["image/png" , "image/jpg" , "image/jpeg"] 17 | if(allowedMimetypes.includes(file.mimetype)){ 18 | cb(null , true) 19 | } 20 | else{ 21 | cb(null , true) 22 | } 23 | } 24 | 25 | 26 | const limits = { 27 | fileSize : 10*1024*1024 28 | } 29 | 30 | 31 | const upload = multer({storage , fileFilter , limits}) 32 | 33 | 34 | module.exports = upload ; -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import { useState } from 'react'; 2 | import Form from './components/Form' 3 | import Pending from './components/Pending' 4 | import Uploaded from './components/Uploaded'; 5 | 6 | function App() { 7 | const [isPending , setIsPending] = useState(false) 8 | const [image , setImage] = useState(null) 9 | const [url , setUrl] = useState(null) 10 | const [error , setError] = useState(false) 11 | return ( 12 |
13 | 14 | 15 | {error ?

internal server error , Refresh the page and try again

: 16 | isPending ? : image && url ? :
} 17 | 18 |
19 | ); 20 | } 21 | 22 | export default App; 23 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@mui/icons-material": "^5.10.16", 7 | "@testing-library/jest-dom": "^5.16.5", 8 | "@testing-library/react": "^13.4.0", 9 | "@testing-library/user-event": "^13.5.0", 10 | "react": "^18.2.0", 11 | "react-dom": "^18.2.0", 12 | "react-dropzone": "^14.2.3", 13 | "react-icons": "^4.7.1", 14 | "react-scripts": "5.0.1", 15 | "web-vitals": "^2.1.4" 16 | }, 17 | "scripts": { 18 | "start": "react-scripts start", 19 | "build": "react-scripts build", 20 | "test": "react-scripts test", 21 | "eject": "react-scripts eject" 22 | }, 23 | "eslintConfig": { 24 | "extends": [ 25 | "react-app", 26 | "react-app/jest" 27 | ] 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | }, 41 | "devDependencies": { 42 | "autoprefixer": "^10.4.13", 43 | "postcss": "^8.4.19", 44 | "tailwindcss": "^3.2.4" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /frontend/src/components/Uploaded.js: -------------------------------------------------------------------------------- 1 | 2 | //import CheckIcon from '@mui/icons-material/Check'; 3 | const Uploaded = ({image , url}) => { 4 | 5 | const copy = async () => { 6 | await navigator.clipboard.writeText(url); 7 | alert('Link copied'); 8 | } 9 | 10 | return ( 11 |
12 |
13 | 14 | 15 | 16 | 17 |

Uploaded Successfully!

18 |
19 |
20 | 21 |
22 |
23 | {url} 24 | 25 |
26 |
27 | ) 28 | } 29 | 30 | export default Uploaded 31 | -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /frontend/src/components/Form.js: -------------------------------------------------------------------------------- 1 | import { useCallback, useState } from 'react' 2 | import {useDropzone} from 'react-dropzone' 3 | import bgimage from '../assets/image.svg' 4 | 5 | const Form = ({image , setImage , isPending , setIsPending , url , setUrl , setError}) => { 6 | 7 | 8 | 9 | const uploadImage = async(image) => { 10 | setError(false) 11 | setIsPending(true) 12 | const formData = new FormData() 13 | formData.append('image' , image) 14 | try{ 15 | const res = await fetch('http://localhost:5000/upload',{ 16 | method : 'POST', 17 | body : formData, 18 | 'content-type': 'multipart/form-data' 19 | }) 20 | if(!res.ok){ 21 | throw Error('Internal Server Error') 22 | } 23 | const data = await res.json() 24 | setUrl(data.path) 25 | setIsPending(false) 26 | }catch(error){ 27 | console.log(error) 28 | setIsPending(false) 29 | setError(true) 30 | } 31 | } 32 | 33 | 34 | 35 | const onDrop = useCallback(async(acceptedFiles) => { 36 | 37 | let file = acceptedFiles[0] 38 | let reader = new FileReader() 39 | 40 | reader.readAsDataURL(file) 41 | reader.onload = () => { 42 | setImage(reader.result) 43 | uploadImage(file) 44 | } 45 | 46 | } , [setImage]) 47 | 48 | const {getRootProps , getInputProps , open} = useDropzone({onDrop , 49 | maxFiles:1 , 50 | accept : {'image/*' : []} , 51 | noClick : true , 52 | noKeyboard : true}) 53 | 54 | return ( 55 |
56 |

Upload your image

57 |

File should be Jpeg , Png...

58 |
59 | 60 | 61 |

Drag & Drop your image here

62 |
63 |

Or

64 | 65 |
66 | ) 67 | } 68 | 69 | export default Form 70 | 71 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /frontend/src/assets/image.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | --------------------------------------------------------------------------------