Modify: FileName header in remote put request should be urlencoded
This commit is contained in:
parent
4b6fbc0de2
commit
6b6bfb4c6b
2 changed files with 11 additions and 6 deletions
|
@ -67,11 +67,6 @@ func GetPolicyByID(ID interface{}) (Policy, error) {
|
|||
return policy, result.Error
|
||||
}
|
||||
|
||||
// IsDirectlyPreview 返回此策略下文件是否可以直接预览(不需要重定向)
|
||||
func (policy *Policy) IsDirectlyPreview() bool {
|
||||
return policy.Type == "local"
|
||||
}
|
||||
|
||||
// AfterFind 找到存储策略后的钩子
|
||||
func (policy *Policy) AfterFind() (err error) {
|
||||
// 解析存储策略设置到OptionsSerialized
|
||||
|
@ -147,3 +142,8 @@ func (policy *Policy) GenerateFileName(uid uint, origin string) string {
|
|||
fileRule = util.Replace(replaceTable, fileRule)
|
||||
return fileRule
|
||||
}
|
||||
|
||||
// IsDirectlyPreview 返回此策略下文件是否可以直接预览(不需要重定向)
|
||||
func (policy *Policy) IsDirectlyPreview() bool {
|
||||
return policy.Type == "local"
|
||||
}
|
||||
|
|
|
@ -101,6 +101,11 @@ func (handler Handler) Put(ctx context.Context, file io.ReadCloser, dst string,
|
|||
return err
|
||||
}
|
||||
|
||||
// 对文件名进行URLEncode
|
||||
fileName, err := url.QueryUnescape(path.Base(dst))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 上传文件
|
||||
resp, err := handler.Client.Request(
|
||||
"POST",
|
||||
|
@ -109,7 +114,7 @@ func (handler Handler) Put(ctx context.Context, file io.ReadCloser, dst string,
|
|||
request.WithHeader(map[string][]string{
|
||||
"Authorization": {credential.Token},
|
||||
"X-Policy": {credential.Policy},
|
||||
"X-FileName": {path.Base(dst)},
|
||||
"X-FileName": {fileName},
|
||||
}),
|
||||
request.WithContentLength(int64(size)),
|
||||
).CheckHTTPResponse(200).DecodeResponse()
|
||||
|
|
Loading…
Reference in a new issue