Last change
on this file since 194776a was 3fc9e50, checked in by KostaFortumanov <kfortumanov@…>, 3 years ago |
prototip part1
|
-
Property mode
set to
100644
|
File size:
954 bytes
|
Line | |
---|
1 | package it.finki.charitable.util;
|
---|
2 |
|
---|
3 | import org.springframework.web.multipart.MultipartFile;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.io.InputStream;
|
---|
7 | import java.nio.file.Files;
|
---|
8 | import java.nio.file.Path;
|
---|
9 | import java.nio.file.Paths;
|
---|
10 | import java.nio.file.StandardCopyOption;
|
---|
11 |
|
---|
12 | public class FileUploadUtil {
|
---|
13 |
|
---|
14 | public static void saveFile(String uploadDir, String fileName,
|
---|
15 | MultipartFile multipartFile) throws IOException {
|
---|
16 | Path uploadPath = Paths.get(uploadDir);
|
---|
17 |
|
---|
18 | if (!Files.exists(uploadPath)) {
|
---|
19 | Files.createDirectories(uploadPath);
|
---|
20 | }
|
---|
21 |
|
---|
22 | try (InputStream inputStream = multipartFile.getInputStream()) {
|
---|
23 | Path filePath = uploadPath.resolve(fileName);
|
---|
24 | Files.copy(inputStream, filePath, StandardCopyOption.REPLACE_EXISTING);
|
---|
25 | } catch (IOException ioe) {
|
---|
26 | throw new IOException("Could not save image file: " + fileName, ioe);
|
---|
27 | }
|
---|
28 | }
|
---|
29 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.