You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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:
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.
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.
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.
Thanks for the change adding the optional perm argument - it solves a real use case.
However, the current implementation applies os.Chmodunconditionally, even when perm is not explicitly provided. This leads to unexpected behavior and breaks backward compatibility (e.g., when writing to /tmp or other existing directories).
Would it make sense to limit chmod to cases where perm is explicitly passed?
In other words:
if perm is provided --> apply chmod
if perm is not provided --> preserve previous behavior (no chmod on existing directories)
This would better match the semantics of an optional parameter and avoid breaking existing code.
Activity
haesuo566 commentedon Oct 27, 2024
Are you saying that we need a method that can provide additional permissions to the SaveUploadedFile method?
reversersed commentedon Oct 29, 2024
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 commentedon Oct 30, 2024
Can i work this issue?
reversersed commentedon Nov 1, 2024
Well, ofc, it's all up to you
refactor(context): add an optional permission parameter to the SaveUp…
refactor(context): add an optional permission parameter to the SaveUp…
phplego commentedon Apr 7, 2026
Thanks for the change adding the optional
permargument - it solves a real use case.However, the current implementation applies
os.Chmodunconditionally, even whenpermis not explicitly provided. This leads to unexpected behavior and breaks backward compatibility (e.g., when writing to/tmpor other existing directories).Would it make sense to limit
chmodto cases wherepermis explicitly passed?In other words:
permis provided --> applychmodpermis not provided --> preserve previous behavior (nochmodon existing directories)This would better match the semantics of an optional parameter and avoid breaking existing code.
An alternative (even safer) approach could be:
chmodonly if the directory was newly created (approach described in SaveUploadedFile: unexpected chmod on existing directories (breaks /tmp usage) #4622 )Both approaches would prevent unintended permission changes on existing system-managed directories.