We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c8ec5cf commit 3f20813Copy full SHA for 3f20813
server.go
@@ -86,6 +86,25 @@ func (s *Server) removeFile(tx *sql.Tx, fileUUID string) error {
86
return nil
87
}
88
89
+func (s *Server) OpenFile(fileUUID string) (io.Reader, error) {
90
+ // Just to check validity.
91
+ _, err := uuid.FromString(fileUUID)
92
+ if err != nil {
93
+ return nil, errors.Wrap(err, "uuid parse")
94
+ }
95
+
96
+ fileLocation := filepath.Join(s.Conf.StorageDir, fileUUID)
97
+ file, err := os.Open(fileLocation)
98
99
+ if os.IsNotExist(err) {
100
+ s.removeFile(nil, fileUUID)
101
+ return nil, ErrFileDoesntExists
102
103
+ return nil, err
104
105
+ return file, nil
106
+}
107
108
// GetFile opens file for reading.
109
//
110
// Note that access using this function is equivalent to access
0 commit comments