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

🤔 file upload #47

Closed
s1ntaxe770r opened this issue Aug 30, 2020 · 2 comments · Fixed by #48
Closed

🤔 file upload #47

s1ntaxe770r opened this issue Aug 30, 2020 · 2 comments · Fixed by #48
Labels
🤔 Question Further information is requested

Comments

@s1ntaxe770r
Copy link

Question description
I looked at the single file upload recipe. How do I specify a directory other than the root
Code snippet (optional)

package main

func main() {

}
@s1ntaxe770r s1ntaxe770r added the 🤔 Question Further information is requested label Aug 30, 2020
@welcome
Copy link

welcome bot commented Aug 30, 2020

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template!

@CreamyMilk
Copy link
Contributor

CreamyMilk commented Aug 31, 2020

You can specify either to save files in a local folder under the current working directory or you can provide a relative path to specify where you wish to save the uploads.

Please🙏 note that you must first create the uploads folder with appropriate read and write permissions before hand 👍.

Linux / Unix folder creation sample

mkdir /tmp/uploads_relative && chmod 0760 /tmp/uploads_relative/

mkdir uploads && chmod 0760 uploads 

Code snippet

// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
// 🤖 Github Repository: https://github.com/gofiber/fiber
// 📌 API Documentation: https://docs.gofiber.io

package main

import (
	"fmt"
	"log"

	"github.com/gofiber/fiber"
)

func main() {
	// Fiber instance
	app := fiber.New()

	// Routes
	app.Post("/", func(c *fiber.Ctx) {
		// Get first file from form field "document":
		file, err := c.FormFile("document")

		// Check for errors:
		if err == nil {
			// 👷 Save file to root directory:
			c.SaveFile(file, fmt.Sprintf("./%s", file.Filename))
			// 👷 Save file inside uploads folder under current working directory:
			c.SaveFile(file, fmt.Sprintf("./uploads/%s", file.Filename))
			// 👷 Save file using a relative path:
			c.SaveFile(file, fmt.Sprintf("/tmp/uploads_relative/%s", file.Filename))
		}
	})

	// Start server
	log.Fatal(app.Listen(3000))
}

@Fenny Fenny closed this as completed in #48 Aug 31, 2020
Fenny pushed a commit that referenced this issue Aug 31, 2020
* Adds example for relative path file uploads  (#47)

* Added sample uploads folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants