Skip to content

Commit

Permalink
add file upload service (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: Rick <[email protected]>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Sep 30, 2024
1 parent 0f8889e commit 6872d45
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import static org.springframework.security.config.Customizer.withDefaults;

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/io/github/devopsws/demo/service/FileService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.github.devopsws.demo.service;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import io.github.devopsws.demo.model.Message;

@RestController
@RequestMapping("/upload")
public class FileService {
@PostMapping("/")
public Message<?> upload(@RequestParam("file") MultipartFile file) {
System.out.println("Received file uploading request");
Message<String> message = new Message<String>();
if (!file.isEmpty()) {
try {
System.out.println("Uploading file size:" + file.getSize());

message.setMessage("ok");
} catch (Exception e) {
message.setMessage(e.getMessage());
}
} else {
message.setMessage("file is empty");
}
return message;
}
}

0 comments on commit 6872d45

Please sign in to comment.