create uploadFolder if not exist
This commit is contained in:
parent
7b1b0f1cc5
commit
a042458499
14
main.go
14
main.go
@ -18,7 +18,7 @@ var uploadFolder string
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
dbpool, err = pgxpool.New(context.Background(), "postgresql://postgres:postgres@172.19.0.3:5432/postgres")
|
dbpool, err = pgxpool.New(context.Background(), "postgresql://postgres:postgres@172.18.0.3:5432/postgres")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -54,6 +54,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
uploadFolder = fmt.Sprintf("%s/videos", currentDir)
|
uploadFolder = fmt.Sprintf("%s/videos", currentDir)
|
||||||
|
|
||||||
|
if _, err := os.Stat(uploadFolder); err != nil {
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
log.Panicf("main: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Mkdir(uploadFolder, 0750); err != nil {
|
||||||
|
log.Panicf("main: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
router.SetTrustedProxies(nil)
|
router.SetTrustedProxies(nil)
|
||||||
|
|
||||||
@ -103,7 +113,7 @@ func receiveChunk(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.OpenFile(fmt.Sprintf("%s/%s", uploadFolder, c.GetHeader("file-name")), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
f, err := os.OpenFile(fmt.Sprintf("%s/%s", uploadFolder, c.GetHeader("file-name")), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0640)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, "")
|
c.JSON(http.StatusInternalServerError, "")
|
||||||
log.Panicf("receiveChunk: %v\n", err)
|
log.Panicf("receiveChunk: %v\n", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user