mirror of
https://github.com/0x1d/rcond.git
synced 2026-03-22 17:07:33 +01:00
feat: implement file upload
This commit is contained in:
25
pkg/system/file.go
Normal file
25
pkg/system/file.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user