Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export default {
MONGODB_URL: process.env.MONGODB_URL || 'mongodb://localhost/amazona',
JWT_SECRET: process.env.JWT_SECRET || 'somethingsecret',
PAYPAL_CLIENT_ID: process.env.PAYPAL_CLIENT_ID || 'sb',
accessKeyId: process.env.accessKeyId || 'accessKeyId',
secretAccessKey: process.env.secretAccessKey || 'secretAccessKey',
};
Copy link
Copy Markdown

@Royal6969 Royal6969 Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basir, It seems like there is a time jump between your video 60 to this video 61 (Udemy course numeration),
because your project has changes that we didn't see before in past videos....
For example, this file called config wasn't there, no?? I think I can remember this file in the past of the course, but I'm not sure if we hid it...
I think there is some video in the middle, before this video.
I'm very sad because I can't implement correctly this feature due that... it is a mess for me

22 changes: 22 additions & 0 deletions backend/routes/uploadRoute.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import express from 'express';
import multer from 'multer';
import multerS3 from 'multer-s3';
import aws from 'aws-sdk';
import config from '../config';

const storage = multer.diskStorage({
destination(req, file, cb) {
Expand All @@ -17,4 +20,23 @@ const router = express.Router();
router.post('/', upload.single('image'), (req, res) => {
res.send(`/${req.file.path}`);
});

aws.config.update({
accessKeyId: config.accessKeyId,
secretAccessKey: config.secretAccessKey,
});
const s3 = new aws.S3();
const storageS3 = multerS3({
s3,
bucket: 'amazona-bucket',
acl: 'public-read',
contentType: multerS3.AUTO_CONTENT_TYPE,
key(req, file, cb) {
cb(null, file.originalname);
},
});
const uploadS3 = multer({ storage: storageS3 });
router.post('/s3', uploadS3.single('image'), (req, res) => {
res.send(req.file.location);
});
export default router;
2 changes: 1 addition & 1 deletion frontend/src/screens/ProductsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function ProductsScreen(props) {
bodyFormData.append('image', file);
setUploading(true);
axios
.post('/api/uploads', bodyFormData, {
.post('/api/uploads/s3', bodyFormData, {
headers: {
'Content-Type': 'multipart/form-data',
},
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"description": "Demo : https://amazonaapp.herokuapp.com/",
"main": "index.js",
"dependencies": {
"aws-sdk": "^2.702.0",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"eslint-plugin-react": "^7.19.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.8.11",
"multer": "^1.4.2"
"multer": "^1.4.2",
"multer-s3": "^2.9.0"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
Expand Down