feat: implement file upload

This commit is contained in:
2025-05-18 19:29:36 +02:00
parent e1fdf51ed0
commit 17a5e98e77
5 changed files with 116 additions and 0 deletions

25
pkg/system/file.go Normal file
View File

@@ -0,0 +1,25 @@
package system
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
// StoreFile stores a file on the file system at the given path.
// If the path does not exist, it will be created.
func StoreFile(path string, content []byte) error {
// Ensure the directory exists
dir := filepath.Dir(path)
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("failed to create directory: %v", err)
}
// Write the file
if err := ioutil.WriteFile(path, content, 0644); err != nil {
return fmt.Errorf("failed to write file: %v", err)
}
return nil
}