Repository navigation
Expand file tree
/
Copy pathMultipart.java
More file actions
79 lines (60 loc) · 1.83 KB
/
Copy pathMultipart.java
File metadata and controls
79 lines (60 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package codesquad.domain;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartFile;
import support.domain.AbstractEntity;
import javax.persistence.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;
import static org.slf4j.LoggerFactory.getLogger;
@Entity
public class Multipart extends AbstractEntity {
private static final Logger log = getLogger(Multipart.class);
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(name = "fk_multipart_writer"))
private User writer;
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(name = "fk_multipart_issue"))
private Issue issue;
@Column
private String originalFilename;
@Column
private String saveName;
private String uploadPath;
public Multipart() {
}
public Multipart(User user, Issue issue, String file, String uploadPath) {
this.writer = user;
this.issue = issue;
this.originalFilename = file;
this.saveName = UUID.randomUUID() + "_" + file;
this.uploadPath = uploadPath;
}
public User getWriter() {
return writer;
}
public String getOriginalFilename() {
return originalFilename;
}
public String getSaveName() {
return saveName;
}
public String getUploadPath() {
return uploadPath;
}
public Issue getIssue() {
return issue;
}
public void setIssue(Issue issue) {
this.issue = issue;
}
public Path add(User user, MultipartFile file) throws IOException {
byte[] bytes = file.getBytes();
Path path = Paths.get(uploadPath + saveName);
log.debug("path :~~~~~ {}", path.toString());
return Files.write(path, bytes);
}
}