박민정

[fix] Fix 504 error

......@@ -5,7 +5,7 @@ import axios from 'axios';
function ImageUpload() {
const imageDropEvent = (files) => {
let imageData = new imageData();
let imageData = new FormData();
const config = {
header: {'content-type': 'multipart/image-data'}
......
......@@ -30,7 +30,7 @@ app.use(cors())
app.use('/api/users', require('./routes/users'));
app.use('/api/image', require('./routes/productImage'));
app.use('/api/image', require('./routes/product'));
// 업로드 하려고
app.use('/uploads', express.static('uploads'));
......
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({
destination: function (req, file, cb) {
cb(null, 'uploads/') // 어느 폴더에 저장할건지
},
filename: function (req, file, cb) {
cb(null, Date.now() + '_' + file.originalname) // 이미지 이름
}
})
var upload = multer({ storage: storage }).single("file");
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;