박민정

[Update] Add product image upload block

...@@ -2312,6 +2312,11 @@ ...@@ -2312,6 +2312,11 @@
2312 "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", 2312 "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
2313 "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==" 2313 "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg=="
2314 }, 2314 },
2315 + "attr-accept": {
2316 + "version": "2.2.2",
2317 + "resolved": "https://registry.npmjs.org/attr-accept/-/attr-accept-2.2.2.tgz",
2318 + "integrity": "sha512-7prDjvt9HmqiZ0cl5CRjtS84sEyhsHP2coDkaZKRKVfCDo9s7iw7ChVmar78Gu9pC4SoR/28wFu/G5JJhTnqEg=="
2319 + },
2315 "autoprefixer": { 2320 "autoprefixer": {
2316 "version": "9.7.5", 2321 "version": "9.7.5",
2317 "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.7.5.tgz", 2322 "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.7.5.tgz",
...@@ -5530,6 +5535,21 @@ ...@@ -5530,6 +5535,21 @@
5530 "schema-utils": "^2.5.0" 5535 "schema-utils": "^2.5.0"
5531 } 5536 }
5532 }, 5537 },
5538 + "file-selector": {
5539 + "version": "0.2.4",
5540 + "resolved": "https://registry.npmjs.org/file-selector/-/file-selector-0.2.4.tgz",
5541 + "integrity": "sha512-ZDsQNbrv6qRi1YTDOEWzf5J2KjZ9KMI1Q2SGeTkCJmNNW25Jg4TW4UMcmoqcg4WrAyKRcpBXdbWRxkfrOzVRbA==",
5542 + "requires": {
5543 + "tslib": "^2.0.3"
5544 + },
5545 + "dependencies": {
5546 + "tslib": {
5547 + "version": "2.2.0",
5548 + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.2.0.tgz",
5549 + "integrity": "sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w=="
5550 + }
5551 + }
5552 + },
5533 "file-uri-to-path": { 5553 "file-uri-to-path": {
5534 "version": "1.0.0", 5554 "version": "1.0.0",
5535 "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", 5555 "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
...@@ -11692,6 +11712,16 @@ ...@@ -11692,6 +11712,16 @@
11692 "scheduler": "^0.19.1" 11712 "scheduler": "^0.19.1"
11693 } 11713 }
11694 }, 11714 },
11715 + "react-dropzone": {
11716 + "version": "11.3.2",
11717 + "resolved": "https://registry.npmjs.org/react-dropzone/-/react-dropzone-11.3.2.tgz",
11718 + "integrity": "sha512-Z0l/YHcrNK1r85o6RT77Z5XgTARmlZZGfEKBl3tqTXL9fZNQDuIdRx/J0QjvR60X+yYu26dnHeaG2pWU+1HHvw==",
11719 + "requires": {
11720 + "attr-accept": "^2.2.1",
11721 + "file-selector": "^0.2.2",
11722 + "prop-types": "^15.7.2"
11723 + }
11724 + },
11695 "react-error-overlay": { 11725 "react-error-overlay": {
11696 "version": "6.0.7", 11726 "version": "6.0.7",
11697 "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.7.tgz", 11727 "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.7.tgz",
......
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
5 "dependencies": { 5 "dependencies": {
6 "antd": "^3.24.1", 6 "antd": "^3.24.1",
7 "axios": "^0.19.2", 7 "axios": "^0.19.2",
8 + "core-js": "^3.6.4",
8 "formik": "^1.5.8", 9 "formik": "^1.5.8",
9 "moment": "^2.24.0", 10 "moment": "^2.24.0",
10 "react": "^16.8.6", 11 "react": "^16.8.6",
12 + "react-app-polyfill": "^1.0.6",
11 "react-dom": "^16.8.6", 13 "react-dom": "^16.8.6",
14 + "react-dropzone": "^11.3.2",
12 "react-icons": "^3.7.0", 15 "react-icons": "^3.7.0",
13 "react-redux": "^7.1.0-rc.1", 16 "react-redux": "^7.1.0-rc.1",
14 "react-router-dom": "^5.0.1", 17 "react-router-dom": "^5.0.1",
...@@ -16,9 +19,7 @@ ...@@ -16,9 +19,7 @@
16 "redux": "^4.0.0", 19 "redux": "^4.0.0",
17 "redux-promise": "^0.6.0", 20 "redux-promise": "^0.6.0",
18 "redux-thunk": "^2.3.0", 21 "redux-thunk": "^2.3.0",
19 - "yup": "^0.27.0", 22 + "yup": "^0.27.0"
20 - "core-js": "^3.6.4",
21 - "react-app-polyfill": "^1.0.6"
22 }, 23 },
23 "scripts": { 24 "scripts": {
24 "start": "react-scripts start", 25 "start": "react-scripts start",
......
1 +import React from 'react'
2 +import Dropzone from 'react-dropzone'
3 +import axios from 'axios';
4 +
5 +function ImageUpload() {
6 +
7 + const imageDropEvent = (files) => {
8 + let imageData = new imageData();
9 +
10 + const config = {
11 + header: {'content-type': 'multipart/image-data'}
12 + }
13 +
14 + // 이미지 전달
15 + axios.post('/api/product/image', imageData, config)
16 + .then(response => {
17 + if (response.data.success) {
18 +
19 + }
20 + else {
21 + alert('파일 저장을 실패했습니다.')
22 + }
23 + })
24 +
25 + }
26 + return (
27 + <div style={ {display:'flex', justifyContent:'space-between'}}>
28 + <Dropzone onDrop={imageDropEvent}>
29 + {({getRootProps, getInputProps}) => (
30 + <section>
31 + <div style={{
32 + width: 300, height: 200, border: '1px solid lightgray', borderRadius: '1em', display: 'flex',
33 + alignItems: 'center', textAlign: 'center', justifyContent: 'center'
34 + }}
35 + {...getRootProps()}>
36 + <input {...getInputProps()} />
37 + <p>이곳을 클릭하여 <br/> 상품 사진을 업로드 해주세요.</p>
38 + </div>
39 + </section>
40 + )}
41 +</Dropzone>
42 + </div>
43 + )
44 +}
45 +
46 +export default ImageUpload
1 import React from 'react'; 1 import React from 'react';
2 import { useState } from 'react'; 2 import { useState } from 'react';
3 import { Typography, Button, Form, Input } from 'antd'; // css 3 import { Typography, Button, Form, Input } from 'antd'; // css
4 - 4 +import ImageUpload from '../../utils/ImageUpload'
5 5
6 const { TextArea } = Input; // 박스크기 조절을 사용자가 임의로 가능하게 함. 6 const { TextArea } = Input; // 박스크기 조절을 사용자가 임의로 가능하게 함.
7 7
8 -// Options 8 +// Select Options
9 const options = [{ key: 1, value: "a" }, 9 const options = [{ key: 1, value: "a" },
10 { key: 2, value: "b" }, 10 { key: 2, value: "b" },
11 {key: 3, value : "c"} 11 {key: 3, value : "c"}
...@@ -44,9 +44,6 @@ function UploadPage() { ...@@ -44,9 +44,6 @@ function UploadPage() {
44 } 44 }
45 45
46 46
47 -
48 -
49 -
50 return ( 47 return (
51 <div style={{ maxWidth: '700px', margin: '2rem auto' }}> 48 <div style={{ maxWidth: '700px', margin: '2rem auto' }}>
52 49
...@@ -56,7 +53,8 @@ function UploadPage() { ...@@ -56,7 +53,8 @@ function UploadPage() {
56 </div> 53 </div>
57 54
58 <Form> 55 <Form>
59 - 56 + {/* 파일업로드 부분은 코드가 길어서 따로 컴포넌트로 만들었습니다. */}
57 + <ImageUpload />
60 <br /> 58 <br />
61 <br /> 59 <br />
62 <label>이름</label> 60 <label>이름</label>
......
...@@ -103,6 +103,11 @@ ...@@ -103,6 +103,11 @@
103 } 103 }
104 } 104 }
105 }, 105 },
106 + "append-field": {
107 + "version": "1.0.0",
108 + "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
109 + "integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY="
110 + },
106 "aproba": { 111 "aproba": {
107 "version": "1.2.0", 112 "version": "1.2.0",
108 "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", 113 "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
...@@ -397,6 +402,43 @@ ...@@ -397,6 +402,43 @@
397 "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", 402 "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
398 "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" 403 "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
399 }, 404 },
405 + "buffer-from": {
406 + "version": "1.1.1",
407 + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
408 + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
409 + },
410 + "busboy": {
411 + "version": "0.2.14",
412 + "resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
413 + "integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=",
414 + "requires": {
415 + "dicer": "0.2.5",
416 + "readable-stream": "1.1.x"
417 + },
418 + "dependencies": {
419 + "isarray": {
420 + "version": "0.0.1",
421 + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
422 + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
423 + },
424 + "readable-stream": {
425 + "version": "1.1.14",
426 + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
427 + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
428 + "requires": {
429 + "core-util-is": "~1.0.0",
430 + "inherits": "~2.0.1",
431 + "isarray": "0.0.1",
432 + "string_decoder": "~0.10.x"
433 + }
434 + },
435 + "string_decoder": {
436 + "version": "0.10.31",
437 + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
438 + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
439 + }
440 + }
441 + },
400 "bytes": { 442 "bytes": {
401 "version": "3.1.0", 443 "version": "3.1.0",
402 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", 444 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
...@@ -604,6 +646,17 @@ ...@@ -604,6 +646,17 @@
604 "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 646 "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
605 "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" 647 "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
606 }, 648 },
649 + "concat-stream": {
650 + "version": "1.6.2",
651 + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
652 + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
653 + "requires": {
654 + "buffer-from": "^1.0.0",
655 + "inherits": "^2.0.3",
656 + "readable-stream": "^2.2.2",
657 + "typedarray": "^0.0.6"
658 + }
659 + },
607 "concurrently": { 660 "concurrently": {
608 "version": "4.1.2", 661 "version": "4.1.2",
609 "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-4.1.2.tgz", 662 "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-4.1.2.tgz",
...@@ -834,6 +887,38 @@ ...@@ -834,6 +887,38 @@
834 "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", 887 "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz",
835 "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=" 888 "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups="
836 }, 889 },
890 + "dicer": {
891 + "version": "0.2.5",
892 + "resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz",
893 + "integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=",
894 + "requires": {
895 + "readable-stream": "1.1.x",
896 + "streamsearch": "0.1.2"
897 + },
898 + "dependencies": {
899 + "isarray": {
900 + "version": "0.0.1",
901 + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
902 + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
903 + },
904 + "readable-stream": {
905 + "version": "1.1.14",
906 + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
907 + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
908 + "requires": {
909 + "core-util-is": "~1.0.0",
910 + "inherits": "~2.0.1",
911 + "isarray": "0.0.1",
912 + "string_decoder": "~0.10.x"
913 + }
914 + },
915 + "string_decoder": {
916 + "version": "0.10.31",
917 + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
918 + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
919 + }
920 + }
921 + },
837 "dot-prop": { 922 "dot-prop": {
838 "version": "4.2.0", 923 "version": "4.2.0",
839 "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", 924 "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz",
...@@ -2644,6 +2729,21 @@ ...@@ -2644,6 +2729,21 @@
2644 "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", 2729 "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
2645 "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" 2730 "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
2646 }, 2731 },
2732 + "multer": {
2733 + "version": "1.4.2",
2734 + "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.2.tgz",
2735 + "integrity": "sha512-xY8pX7V+ybyUpbYMxtjM9KAiD9ixtg5/JkeKUTD6xilfDv0vzzOFcCp4Ljb1UU3tSOM3VTZtKo63OmzOrGi3Cg==",
2736 + "requires": {
2737 + "append-field": "^1.0.0",
2738 + "busboy": "^0.2.11",
2739 + "concat-stream": "^1.5.2",
2740 + "mkdirp": "^0.5.1",
2741 + "object-assign": "^4.1.1",
2742 + "on-finished": "^2.3.0",
2743 + "type-is": "^1.6.4",
2744 + "xtend": "^4.0.0"
2745 + }
2746 + },
2647 "nan": { 2747 "nan": {
2648 "version": "2.14.0", 2748 "version": "2.14.0",
2649 "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", 2749 "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
...@@ -3717,6 +3817,11 @@ ...@@ -3717,6 +3817,11 @@
3717 "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", 3817 "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
3718 "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" 3818 "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
3719 }, 3819 },
3820 + "streamsearch": {
3821 + "version": "0.1.2",
3822 + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
3823 + "integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
3824 + },
3720 "string-width": { 3825 "string-width": {
3721 "version": "1.0.2", 3826 "version": "1.0.2",
3722 "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", 3827 "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
...@@ -3913,6 +4018,11 @@ ...@@ -3913,6 +4018,11 @@
3913 "mime-types": "~2.1.24" 4018 "mime-types": "~2.1.24"
3914 } 4019 }
3915 }, 4020 },
4021 + "typedarray": {
4022 + "version": "0.0.6",
4023 + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
4024 + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
4025 + },
3916 "undefsafe": { 4026 "undefsafe": {
3917 "version": "2.0.3", 4027 "version": "2.0.3",
3918 "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.3.tgz", 4028 "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.3.tgz",
...@@ -4178,6 +4288,11 @@ ...@@ -4178,6 +4288,11 @@
4178 "integrity": "sha1-SWsswQnsqNus/i3HK2A8F8WHCtQ=", 4288 "integrity": "sha1-SWsswQnsqNus/i3HK2A8F8WHCtQ=",
4179 "dev": true 4289 "dev": true
4180 }, 4290 },
4291 + "xtend": {
4292 + "version": "4.0.2",
4293 + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
4294 + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
4295 + },
4181 "y18n": { 4296 "y18n": {
4182 "version": "4.0.0", 4297 "version": "4.0.0",
4183 "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", 4298 "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
25 "jsonwebtoken": "^8.5.1", 25 "jsonwebtoken": "^8.5.1",
26 "moment": "^2.24.0", 26 "moment": "^2.24.0",
27 "mongoose": "^5.4.20", 27 "mongoose": "^5.4.20",
28 + "multer": "^1.4.2",
28 "react-redux": "^5.0.7", 29 "react-redux": "^5.0.7",
29 "saslprep": "^1.0.3", 30 "saslprep": "^1.0.3",
30 "supports-color": "^7.1.0" 31 "supports-color": "^7.1.0"
......