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

c.SaveUploadedFile permissions #4068

Open
reversersed opened this issue Oct 7, 2024 · 4 comments
Open

c.SaveUploadedFile permissions #4068

reversersed opened this issue Oct 7, 2024 · 4 comments

Comments

@reversersed
Copy link

Description

I run into problem when I saving uploaded file to a folder and trying to get it from nginx it gives me permission error.
I found out that folders created by SaveUploadedFile function has 0750 rights, which I can't get access to.
After changing folder permissions problem is gone. Is there some way to specify the permissions for folders created besides manually creating it or chaning permissions by hand?

How to reproduce

package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	g := gin.Default()
	g.POST("/upload", func(c *gin.Context) {
	        form, _ := c.MultipartForm()
                file := form.File["file"]

		c.SaveUploadedFile(file, "data/files/img.png")
                c.Status(http.StatusCreated)
	})
	g.Run(":9000")
}

Expectations

I excepted there is some method that allows to specify folder permissions I need (e.g. SaveUploadedFile(file *multipart.FileHeader, dst string, perm ...os.FileMode)).
You could specify permissions you need or leave it empty and get default (as it now) permissions.

Actual result

I got hard-written permissions made by source code:

if err = os.MkdirAll(filepath.Dir(dst), 0750); err != nil {
		return err
	}

Environment

  • go version: 1.22
  • gin version (or commit ref): v1.10.0
  • operating system: linux/windows
@haesuo566
Copy link

Are you saying that we need a method that can provide additional permissions to the SaveUploadedFile method?

@reversersed
Copy link
Author

Are you saying that we need a method that can provide additional permissions to the SaveUploadedFile method?

We could have an additional method like SaveUploadedFileWithPermission which can allow us to decide what permissions we need for file are. Or just modify existing method adding 3rd parameter allowing us to override default permissions. The details is up to maintainers.

@haesuo566
Copy link

Are you saying that we need a method that can provide additional permissions to the SaveUploadedFile method?

We could have an additional method like SaveUploadedFileWithPermission which can allow us to decide what permissions we need for file are. Or just modify existing method adding 3rd parameter allowing us to override default permissions. The details is up to maintainers.

Can i work this issue?

@reversersed
Copy link
Author

Are you saying that we need a method that can provide additional permissions to the SaveUploadedFile method?

We could have an additional method like SaveUploadedFileWithPermission which can allow us to decide what permissions we need for file are. Or just modify existing method adding 3rd parameter allowing us to override default permissions. The details is up to maintainers.

Can i work this issue?

Well, ofc, it's all up to you

haesuo566 added a commit to haesuo566/gin that referenced this issue Nov 7, 2024
haesuo566 pushed a commit to haesuo566/gin that referenced this issue Nov 7, 2024
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