package Util
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// WriteFile to disk
|
|
func WriteFile(contents []byte) (string, error) {
|
|
var (
|
|
fileName string
|
|
filePath string
|
|
f *os.File
|
|
err error
|
|
)
|
|
|
|
fileName = RandomString(32)
|
|
|
|
filePath = fmt.Sprintf(
|
|
"/app/attachments/%s",
|
|
fileName,
|
|
)
|
|
|
|
f, err = os.Create(filePath)
|
|
|
|
if err != nil {
|
|
return fileName, err
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
_, err = f.Write(contents)
|
|
|
|
if err != nil {
|
|
return fileName, err
|
|
}
|
|
|
|
return fileName, nil
|
|
}
|