Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 Unable to access uploaded files while running fiber #221

Closed
hyingreborn opened this issue Mar 13, 2020 · 6 comments
Closed

🐞 Unable to access uploaded files while running fiber #221

hyingreborn opened this issue Mar 13, 2020 · 6 comments

Comments

@hyingreborn
Copy link

hyingreborn commented Mar 13, 2020

Fiber version/commit
1.8.2

Issue description
Unable to access static folder uploaded files before restarting fiber

Expected behavior
I upload some static files to static folder,then unable to access these files, until restart the fiber server

Steps to reproduce

Code snippet

package main

import "github.com/gofiber/fiber"

func main() {
  app := fiber.New()
  // set static path
  app.Static("/", "./public")
  // upload route
  app.Post("/api/v1/upload", func(c *fiber.Ctx){
    // ...
    c.SaveFile(file, "./public/upload/hashString.jpg")
  })
  // ...
}
@hyingreborn
Copy link
Author

By the way, I'm also using minio for storage, and its method requires providing a path to the file. C.formfile () doesn't seem to have a temporary path to the file

@Fenny Fenny changed the title 🐞 Unable to access static folder uploaded files before restarting fiber 🐞 Unable to access uploaded files while running fiber Mar 14, 2020
@Fenny
Copy link
Member

Fenny commented Mar 14, 2020

I tried to re-produce your issue but it works like expected?

create main.go
package main

import (
  "fmt"

  "github.com/gofiber/fiber"
)

func main() {
  app := fiber.New()
  app.Post("/", func(c *fiber.Ctx) {
    if form, err := c.MultipartForm(); err == nil {
      files := form.File["documents"]
      for _, file := range files {
        fmt.Println(file.Filename, file.Size, file.Header["Content-Type"][0])
        // => "main.go" 546 "application/octet-stream"
        c.SaveFile(file, fmt.Sprintf("./copy_%s", file.Filename))
      }
    }
  })
  app.Listen(3000)
}

// curl -F [email protected] http://localhost:3000

Run:

curl -F [email protected] http://localhost:3000

Writing or accessing copy_main.go seems to work fine?

@hyingreborn
Copy link
Author

package main

import (
  "fmt"

  "github.com/gofiber/fiber"
)

func main() {
  app := fiber.New()
  app.Static("/", "./public")
  app.Post("/", func(c *fiber.Ctx) {
    if form, err := c.MultipartForm(); err == nil {
      files := form.File["documents"]
      for _, file := range files {
        fmt.Println(file.Filename, file.Size, file.Header["Content-Type"][0])
        // => "main.go" 546 "application/octet-stream"
        c.SaveFile(file, fmt.Sprintf("./public/upload/copy_%s", file.Filename))
      }
    }
  })
  app.Listen(3000)
}

Then visit : http://localhost:3000/upload/filename.extname

Try uploading an image to the Static directory? @Fenny

@Fenny
Copy link
Member

Fenny commented Mar 14, 2020

One second, I think I found the problem.

This was referenced Mar 15, 2020
@Fenny
Copy link
Member

Fenny commented Mar 15, 2020

This should be fixed in v1.8.32 https:/gofiber/fiber/releases/tag/v1.8.32
Feel free to re-open this issue if you still have problems regarding this issue.

@Fenny Fenny closed this as completed Mar 15, 2020
@Fenny Fenny added the solved label Mar 15, 2020
@hyingreborn
Copy link
Author

Thanks! The problem was fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants