@@ -179,9 +179,50 @@ This part shows list of reviews by users for each products. also it provides a f
17917929 . save review in product.reviews
18018030 . update avg rating
181181
182- ### Part 25- Upload images
183-
184- Admin shoud be able to uploads photos from their computer. This section teaches this feature.
182+ ### Part 25- Upload Product Images On Local Server
183+
184+ Admin shoud be able to uploads photos from their computer. This section is about uploading images on local server ans aws s3 cloud server.
185+
186+ 1 . npm install multer
187+ 2 . routes/uploadRoute.js
188+ 3 . import express and multer
189+ 4 . create disk storage with Date.now().jpg as filename
190+ 5 . set upload as multer({ storage })
191+ 6 . router.post('/', upload.single('image'))
192+ 7 . return req.file.path
193+ 8 . server.js
194+ 9 . app.use('/api/uploads',uploadRoute)
195+ 10 . ProductsScreen.js
196+ 11 . create state hook for uploading
197+ 12 . create input image file and onChange handler
198+ 13 . define handleUploadImage function
199+ 14 . prepare file for upload
200+ 15 . axios post file as multipart/form-data
201+ 16 . set image and set uploading
202+ 17 . check result
203+
204+ ### Part 26- Upload Product Images On AWS S3
205+
206+ This section is about uploading images amazon aws s3 cloud server.
207+
208+ 1 . create aws account
209+ 2 . open https://s3.console.aws.amazon.com
210+ 3 . create public bucket as amazona
211+ 4 . create api key and secret
212+ 5 . past it into .env as accessKeyId and secretAccessKey
213+ 6 . move dotenv to config.js
214+ 7 . add accessKeyId and secretAccessKey to config.js
215+ 8 . npm install aws-sdk multer-s3
216+ 9 . routes/uploadRoute.js
217+ 10 . set aws.config.update to config values
218+ 11 . create s3 from new aws.S3()
219+ 12 . create storageS3 from multerS3 by setting s3, bucket and acl
220+ 13 . set uploadS3 as multer({ storage: storageS3 })
221+ 14 . router.post('/s3', uploadS3.single('image'))
222+ 15 . return req.file.location
223+ 16 . ProductsScreen.js
224+ 17 . on handleUploadImage set axios.post('api/uploads/s3')
225+ 18 . check result on website and s3
185226
186227## Summary
187228
0 commit comments