ryujihye
@ryujihye
Reviews Written
4
Average Rating
5.0
Posts
Q&A
์ด๋ฏธ์ง ๋ก๋ฉ ์ค๋ฅ(ERR_SSL_PROTOCOL_ERROR)
๊ฐ์ ์ฒ์๋ถํฐ ๋ฐ๋ผ์ ๋ค์ ์์ฑํ๊ณ ๋ค๋ฅธ ๋ถ๋ค์ ๊ธ์ ๋ณด๋ฉด์ ํด๊ฒฐํ์ต๋๋ค ์ฐธ๊ณ ํ ๊ธ : https://www.inflearn.com/questions/445195 Client - FileUpload.js import React, { useState } from "react"; import Dropzone from "react-dropzone"; import { PlusOutlined } from "@ant-design/icons"; import axios from "axios"; function FileUpload() { const [Images, setImages] = useState([]); const dropHandler = (files) => { let formData = new FormData(); const config = { header: { "content-type": "multipart/fomr-data" }, }; formData.append("file", files[0]); axios .post("/api/product/image", formData, config) .then((response) => { if (response.data.success) { console.log(response.data); setImages([...Images, response.data.filePath]); } else { alert("ํ์ผ์ ์ ์ฅํ๋๋ฐ ์คํจํ์ต๋๋ค."); } }); }; return ( div style={{ display: "flex", justifyContent: "space-between" }}> Dropzone onDrop={dropHandler}> {({ getRootProps, getInputProps }) => ( section> div style={{ width: 300, height: 240, border: "1px solid lightgray", display: "flex", alignItems: "center", justifyContent: "center", }} {...getRootProps()} > input {...getInputProps()} /> PlusOutlined style={{ fontSize: "3rem", display: "flex", alignSelf: "center", }} /> div> section> )} Dropzone> div style={{ display: "flex", width: "350px", height: "240px", overflowX: "scroll", }} > {Images.map((image, index) => { return ( div key={index}> img style={{ minWidth: "300px", width: "300px", height: "240px" }} src={`http://localhost:5000/${image}`} /> div> ); })} div> div> ); } export default FileUpload; Server - index.js app.use("/api/product", require("./routes/product")); app.use("/uploads", express.static("uploads")); - routes/product const express = require("express"); 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;
- 0
- 2
- 4.2K
Q&A
prop.history.push('/')๊ฐ ์๋์ด ์๋์๋ ๋ถ๋ค ์ฐธ๊ณ ํ์ธ์
๊ฐ์ฌํฉ๋๋ค ๋๋ถ์ ํด๊ฒฐํ ์ ์์์ต๋๋ค. ์ ๋ ์ด๋ฐ ์์ผ๋ก ๊ณ ์ณค์ต๋๋ค. import React, { useState } from "react"; import { useDispatch } from "react-redux"; import { registerUser } from "../../../_action/user_action"; import { useNavigate } from "react-router-dom"; function RegisterPage(props) { const dispatch = useDispatch(); const navigate = useNavigate(); const [Email, setEmail] = useState(""); const [Name, setName] = useState(""); const [Password, setPassword] = useState(""); const [ConfirmPassword, setConfirmPassword] = useState(""); const onEmailHandler = (event) => { setEmail(event.currentTarget.value); }; const onNameHandler = (event) => { setName(event.currentTarget.value); }; const onPasswordHandler = (event) => { setPassword(event.currentTarget.value); }; const onConfirmPasswordHandler = (event) => { setConfirmPassword(event.currentTarget.value); }; const onSubmitHandler = (event) => { event.preventDefault(); if (Password !== ConfirmPassword) { return alert("๋น๋ฐ๋ฒํธ์ ๋น๋ฐ๋ฒํธ ํ์ธ์ ๊ฐ์์ผ ํฉ๋๋ค."); } let body = { email: Email, password: Password, name: Name, }; dispatch(registerUser(body)).then((response) => { if (response.payload.success) { alert("ํ์๊ฐ์ ์ด ์๋ฃ๋์์ต๋๋ค."); navigate("/login"); } else { alert("ํ์๊ฐ์ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค."); } }); }; return ( Email Name Password Confirm Password ํ์ ๊ฐ์ ); } export default RegisterPage;
- 5
- 1
- 1.1K




