Skip to content

Commit

Permalink
ensure uploads/
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankFang committed Oct 14, 2021
1 parent 656760a commit ef92acf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/controllers/files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func FilesController(c *gin.Context) {
log.Fatal(err)
}
filename := uuid.New().String()
uploads := filepath.Join(dir, "uploads")
err = os.MkdirAll(uploads, os.ModePerm)
if err != nil {
log.Fatal(err)
}
fullpath := path.Join("uploads", filename+filepath.Ext(file.Filename))
fileErr := c.SaveUploadedFile(file, filepath.Join(dir, fullpath))
if fileErr != nil {
Expand Down
5 changes: 5 additions & 0 deletions server/controllers/texts_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func TextsController(c *gin.Context) {
log.Fatal(err)
}
filename := uuid.New().String()
uploads := filepath.Join(dir, "uploads")
err = os.MkdirAll(uploads, os.ModePerm)
if err != nil {
log.Fatal(err)
}
fullpath := path.Join("uploads", filename+".txt")
err = ioutil.WriteFile(filepath.Join(dir, fullpath), []byte(json.Raw), 0644)
if err != nil {
Expand Down

0 comments on commit ef92acf

Please sign in to comment.