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 23:15:31 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
80d47a1ab40cbe99a89c3c31e16be15e6caf07fa
80d47a1a
1 parent
0d499a22
[update] Store image to server
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
4 deletions
We-Shop/client/src/components/utils/ImageUpload.js
We-Shop/server/index.js
We-Shop/server/routes/productImage.js → We-Shop/server/routes/product.js
We-Shop/client/src/components/utils/ImageUpload.js
View file @
80d47a1
...
...
@@ -5,17 +5,18 @@ import axios from 'axios';
function
ImageUpload
()
{
const
imageDropEvent
=
(
files
)
=>
{
let
imageData
=
new
image
Data
();
let
imageData
=
new
Form
Data
();
const
config
=
{
header
:
{
'content-type'
:
'multipart/image-data'
}
}
imageData
.
append
(
"file"
,
files
[
0
])
// 이미지 전달
axios
.
post
(
'/api/product/image'
,
imageData
,
config
)
.
then
(
response
=>
{
if
(
response
.
data
.
success
)
{
console
.
log
(
response
.
data
)
}
else
{
alert
(
'파일 저장을 실패했습니다.'
)
...
...
We-Shop/server/index.js
View file @
80d47a1
...
...
@@ -30,6 +30,7 @@ app.use(cors())
app
.
use
(
'/api/users'
,
require
(
'./routes/users'
));
app
.
use
(
'/api/product'
,
require
(
'./routes/product'
));
// 이미지 가져오려고
...
...
We-Shop/server/routes/product
Image
.js
→
We-Shop/server/routes/product.js
View file @
80d47a1
...
...
@@ -2,6 +2,7 @@ const express = require('express');
const
{
User
}
=
require
(
"../models/User"
);
const
{
auth
}
=
require
(
"../middleware/auth"
);
const
router
=
express
.
Router
();
const
multer
=
require
(
'multer'
);
var
storage
=
multer
.
diskStorage
({
...
...
@@ -13,12 +14,12 @@ var storage = multer.diskStorage({
}
})
var
upload
=
multer
({
storage
:
storage
})
var
upload
=
multer
({
storage
:
storage
}).
single
(
"file"
);
router
.
post
(
'/image'
,
(
req
,
res
)
=>
{
// 클라이언트로부터 받은 이미지 저장
upload
(
req
,
res
,
err
=>
{
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
})
}
...
...
Please
register
or
login
to post a comment