Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박민정
/
We-Shop
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박민정
2021-06-09 22:34:14 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f60c37ed24fd61a1abab56cb48201bcb0ff1feda
f60c37ed
1 parent
20e62fef
[feat] Store the image to server
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
We-Shop/server/index.js
We-Shop/server/routes/productImage.js
We-Shop/server/index.js
View file @
f60c37e
...
...
@@ -30,9 +30,9 @@ app.use(cors())
app
.
use
(
'/api/users'
,
require
(
'./routes/users'
));
app
.
use
(
'/api/image'
,
require
(
'./routes/productImage'
));
// 이미지 가져오려고
// 업로드 하려고
app
.
use
(
'/uploads'
,
express
.
static
(
'uploads'
));
if
(
process
.
env
.
NODE_ENV
===
"production"
)
{
...
...
@@ -42,6 +42,7 @@ if (process.env.NODE_ENV === "production") {
});
}
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`Server ---> http://localhost:
${
port
}
`
)
});
\ No newline at end of file
...
...
We-Shop/server/routes/productImage.js
0 → 100644
View file @
f60c37e
const
express
=
require
(
'express'
);
const
{
User
}
=
require
(
"../models/User"
);
const
{
auth
}
=
require
(
"../middleware/auth"
);
const
router
=
express
.
Router
();
var
storage
=
multer
.
diskStorage
({
destination
:
function
(
req
,
file
,
cb
)
{
cb
(
null
,
'uploads/'
)
// 어느 폴더에 저장할건지
},
filename
:
function
(
req
,
file
,
cb
)
{
cb
(
null
,
Date
.
now
()
+
'_'
+
file
.
originalname
)
// 이미지 이름
}
})
var
upload
=
multer
({
storage
:
storage
})
router
.
post
(
'/image'
,
(
req
,
res
)
=>
{
// 클라이언트로부터 받은 이미지 저장
upload
(
req
,
res
,
err
=>
{
if
(
err
)
return
req
.
json
({
success
:
false
,
err
})
return
res
.
json
({
success
:
true
,
filePath
:
res
.
req
.
file
.
path
,
fileName
:
res
.
req
.
file
.
filename
})
}
)
})
module
.
exports
=
router
;
Please
register
or
login
to post a comment