File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed
src/main/java/io/github/devopsws/demo/service Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ Run with Maven command:
13
13
mvn spring-boot:run
14
14
```
15
15
16
+ Change the listen port:
17
+ ``` shell
18
+ java -jar demo.jar --server.port=8081
19
+ ```
20
+
16
21
## OpenAPI definition
17
22
You can visit it via: http://localhost:8080/v3/api-docs
18
23
Original file line number Diff line number Diff line change 1
1
package io .github .devopsws .demo .service ;
2
2
3
+ import java .io .FileOutputStream ;
4
+
5
+ import org .springframework .util .FileCopyUtils ;
3
6
import org .springframework .web .bind .annotation .PostMapping ;
4
7
import org .springframework .web .bind .annotation .RequestMapping ;
5
8
import org .springframework .web .bind .annotation .RequestParam ;
@@ -16,8 +19,11 @@ public Message<?> upload(@RequestParam("file") MultipartFile file) {
16
19
System .out .println ("Received file uploading request" );
17
20
Message <String > message = new Message <String >();
18
21
if (!file .isEmpty ()) {
19
- try {
20
- System .out .println ("Uploading file size:" + file .getSize ());
22
+ String filename = file .getOriginalFilename ();
23
+ try (FileOutputStream out = new FileOutputStream (filename )) {
24
+ System .out .println ("Uploading file size: " + file .getSize () + ", name: " + filename );
25
+
26
+ FileCopyUtils .copy (file .getInputStream (), out );
21
27
22
28
message .setMessage ("ok" );
23
29
} catch (Exception e ) {
Original file line number Diff line number Diff line change
1
+ package io .github .devopsws .demo .service ;
2
+
3
+ import org .springframework .web .bind .annotation .GetMapping ;
4
+ import org .springframework .web .bind .annotation .RestController ;
5
+
6
+ @ RestController ("/" )
7
+ public class RootService {
8
+
9
+ @ GetMapping ("" )
10
+ public String index () {
11
+ return "Let's learn spring boot!" ;
12
+ }
13
+ }
You can’t perform that action at this time.
0 commit comments