質問編集履歴

2

誤字

2020/06/21 14:56

投稿

tennis
tennis

スコア19

test CHANGED
File without changes
test CHANGED
@@ -232,10 +232,4 @@
232
232
 
233
233
  ```
234
234
 
235
- ### 問題
236
-
237
- ファイルをアップロードると以下のうなエラーが出ます。
235
+ Spring側でうまく受け取れず、困っていまろしくお願いします。
238
-
239
- org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
240
-
241
- よろしくお願いします。

1

誤字

2020/06/21 14:56

投稿

tennis
tennis

スコア19

test CHANGED
File without changes
test CHANGED
@@ -2,6 +2,236 @@
2
2
 
3
3
  Vue.jsからCSVを読み込み、SpringBoot側で受け取りたいです。
4
4
 
5
+ ```Vue
6
+
7
+ <template>
8
+
9
+ <b-card
10
+
11
+ header="外部ファイルの読み込み"
12
+
13
+ >
14
+
15
+ <v-list two-line subheader dense>
16
+
17
+ <v-subheader>外部ファイルを読み込む</v-subheader>
18
+
19
+ <v-list-item>
20
+
21
+ <v-list-item-content>
22
+
23
+ <v-list-item-title>
24
+
25
+ <v-file-input
26
+
27
+ label="File input"
28
+
29
+ v-model="file"
30
+
31
+ name=file
32
+
33
+ placeholder="読み込みたいファイル"
34
+
35
+ ></v-file-input>
36
+
37
+ </v-list-item-title>
38
+
39
+ </v-list-item-content>
40
+
41
+ <v-list-item-action-text class="pl-4">
42
+
43
+ <b-button
44
+
45
+ variant="outline-success"
46
+
47
+ :disabled="file === ''"
48
+
49
+ size="sm"
50
+
51
+ @click="uploadFile()"
52
+
53
+ >ファイルを読み込む
54
+
55
+ </b-button>
56
+
57
+ </v-list-item-action-text>
58
+
59
+ </v-list-item>
60
+
61
+ <v-divider></v-divider>
62
+
63
+ </v-list>
64
+
65
+ </b-card>
66
+
67
+ </template>
68
+
69
+ <script>
70
+
71
+ export default {
72
+
73
+ data() {
74
+
75
+ return {
76
+
77
+ file: "",
78
+
79
+ };
80
+
81
+ },
82
+
83
+ methods: {
84
+
85
+ uploadFile() {
86
+
87
+ this.$axios.post('/user/impoertUser', this.file, {
88
+
89
+ headers: { 'Content-Type': 'multipart/form-data' }
90
+
91
+ }).then((res) => {
92
+
93
+ console.log(res.data)
94
+
95
+ })
96
+
97
+ }
98
+
99
+ }
100
+
101
+ };
102
+
103
+ </script>
104
+
105
+
106
+
107
+ ```
108
+
109
+ ```Java
110
+
111
+ package com.example.controller;
112
+
113
+
114
+
115
+ import java.io.BufferedReader;
116
+
117
+ import java.io.IOException;
118
+
119
+ import java.io.InputStream;
120
+
121
+ import java.io.InputStreamReader;
122
+
123
+ import java.io.Reader;
124
+
125
+
126
+
127
+ import org.springframework.beans.factory.annotation.Autowired;
128
+
129
+ import org.springframework.web.bind.annotation.RequestMapping;
130
+
131
+ import org.springframework.web.bind.annotation.RequestMethod;
132
+
133
+ import org.springframework.web.bind.annotation.RequestParam;
134
+
135
+ import org.springframework.web.bind.annotation.RestController;
136
+
137
+ import org.springframework.web.multipart.MultipartFile;
138
+
139
+
140
+
141
+ import com.example.form.RegisterUserForm;
142
+
143
+ import com.example.service.RegisterUserService;
144
+
145
+
146
+
147
+ @RestController
148
+
149
+ @RequestMapping("/user")
150
+
151
+ public class ImportCSVController {
152
+
153
+
154
+
155
+ @Autowired
156
+
157
+ private RegisterUserService registerUserService;
158
+
159
+
160
+
161
+ @RequestMapping(value = "/importUser", headers = "Content-Type= multipart/form-data", method = RequestMethod.POST)
162
+
163
+ public void importUser(@RequestParam("file") MultipartFile uploadFile) {
164
+
165
+
166
+
167
+ System.err.println(uploadFile);
168
+
169
+
170
+
171
+ String line = null;
172
+
173
+
174
+
175
+ try {
176
+
177
+ InputStream stream = uploadFile.getInputStream();
178
+
179
+ Reader reader = new InputStreamReader(stream);
180
+
181
+ BufferedReader buf= new BufferedReader(reader);
182
+
183
+
184
+
185
+ line = buf.readLine();
186
+
187
+ while((line = buf.readLine()) != null) {
188
+
189
+
190
+
191
+ String[] data = line.split(",", 0);
192
+
193
+
194
+
195
+ RegisterUserForm form = new RegisterUserForm();
196
+
197
+
198
+
199
+ form.setUserName(data[0]);
200
+
201
+ form.setMailAddress(data[1]);
202
+
203
+ form.setPassword(data[2]);
204
+
205
+ registerUserService.registerUser(form);
206
+
207
+
208
+
209
+ }
210
+
211
+
212
+
213
+ } catch (IOException e) {
214
+
215
+
216
+
217
+ line = "Can't read contents.";
218
+
219
+ e.printStackTrace();
220
+
221
+
222
+
223
+ }
224
+
225
+
226
+
227
+ }
228
+
229
+ }
230
+
231
+
232
+
233
+ ```
234
+
5
235
  ### 問題
6
236
 
7
237
  ファイルをアップロードすると以下のようなエラーが出ます。
@@ -9,235 +239,3 @@
9
239
  org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
10
240
 
11
241
  よろしくお願いします。
12
-
13
-
14
-
15
- ```Vue
16
-
17
- <template>
18
-
19
- <b-card
20
-
21
- header="外部ファイルの読み込み"
22
-
23
- >
24
-
25
- <v-list two-line subheader dense>
26
-
27
- <v-subheader>外部ファイルを読み込む</v-subheader>
28
-
29
- <v-list-item>
30
-
31
- <v-list-item-content>
32
-
33
- <v-list-item-title>
34
-
35
- <v-file-input
36
-
37
- label="File input"
38
-
39
- v-model="file"
40
-
41
- name=file
42
-
43
- placeholder="読み込みたいファイル"
44
-
45
- ></v-file-input>
46
-
47
- </v-list-item-title>
48
-
49
- </v-list-item-content>
50
-
51
- <v-list-item-action-text class="pl-4">
52
-
53
- <b-button
54
-
55
- variant="outline-success"
56
-
57
- :disabled="file === ''"
58
-
59
- size="sm"
60
-
61
- @click="uploadFile()"
62
-
63
- >ファイルを読み込む
64
-
65
- </b-button>
66
-
67
- </v-list-item-action-text>
68
-
69
- </v-list-item>
70
-
71
- <v-divider></v-divider>
72
-
73
- </v-list>
74
-
75
- </b-card>
76
-
77
- </template>
78
-
79
- <script>
80
-
81
- export default {
82
-
83
- data() {
84
-
85
- return {
86
-
87
- file: "",
88
-
89
- };
90
-
91
- },
92
-
93
- methods: {
94
-
95
- uploadFile() {
96
-
97
- this.$axios.post('/user/impoertUser', this.file, {
98
-
99
- headers: { 'Content-Type': 'multipart/form-data' }
100
-
101
- }).then((res) => {
102
-
103
- console.log(res.data)
104
-
105
- })
106
-
107
- }
108
-
109
- }
110
-
111
- };
112
-
113
- </script>
114
-
115
-
116
-
117
- ```
118
-
119
- ```Java
120
-
121
- package com.example.controller;
122
-
123
-
124
-
125
- import java.io.BufferedReader;
126
-
127
- import java.io.IOException;
128
-
129
- import java.io.InputStream;
130
-
131
- import java.io.InputStreamReader;
132
-
133
- import java.io.Reader;
134
-
135
-
136
-
137
- import org.springframework.beans.factory.annotation.Autowired;
138
-
139
- import org.springframework.web.bind.annotation.RequestMapping;
140
-
141
- import org.springframework.web.bind.annotation.RequestMethod;
142
-
143
- import org.springframework.web.bind.annotation.RequestParam;
144
-
145
- import org.springframework.web.bind.annotation.RestController;
146
-
147
- import org.springframework.web.multipart.MultipartFile;
148
-
149
-
150
-
151
- import com.example.form.RegisterUserForm;
152
-
153
- import com.example.service.RegisterUserService;
154
-
155
-
156
-
157
- @RestController
158
-
159
- @RequestMapping("/user")
160
-
161
- public class ImportCSVController {
162
-
163
-
164
-
165
- @Autowired
166
-
167
- private RegisterUserService registerUserService;
168
-
169
-
170
-
171
- @RequestMapping(value = "/importUser", headers = "Content-Type= multipart/form-data", method = RequestMethod.POST)
172
-
173
- public void importUser(@RequestParam("file") MultipartFile uploadFile) {
174
-
175
-
176
-
177
- System.err.println(uploadFile);
178
-
179
-
180
-
181
- String line = null;
182
-
183
-
184
-
185
- try {
186
-
187
- InputStream stream = uploadFile.getInputStream();
188
-
189
- Reader reader = new InputStreamReader(stream);
190
-
191
- BufferedReader buf= new BufferedReader(reader);
192
-
193
-
194
-
195
- line = buf.readLine();
196
-
197
- while((line = buf.readLine()) != null) {
198
-
199
-
200
-
201
- String[] data = line.split(",", 0);
202
-
203
-
204
-
205
- RegisterUserForm form = new RegisterUserForm();
206
-
207
-
208
-
209
- form.setUserName(data[0]);
210
-
211
- form.setMailAddress(data[1]);
212
-
213
- form.setPassword(data[2]);
214
-
215
- registerUserService.registerUser(form);
216
-
217
-
218
-
219
- }
220
-
221
-
222
-
223
- } catch (IOException e) {
224
-
225
-
226
-
227
- line = "Can't read contents.";
228
-
229
- e.printStackTrace();
230
-
231
-
232
-
233
- }
234
-
235
-
236
-
237
- }
238
-
239
- }
240
-
241
-
242
-
243
- ```