mirror of
				https://github.com/cloudreve/cloudreve.git
				synced 2025-11-04 13:16:02 +08:00 
			
		
		
		
	Modify: FileName header in remote put request should be urlencoded
This commit is contained in:
		@ -67,11 +67,6 @@ func GetPolicyByID(ID interface{}) (Policy, error) {
 | 
				
			|||||||
	return policy, result.Error
 | 
						return policy, result.Error
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// IsDirectlyPreview 返回此策略下文件是否可以直接预览(不需要重定向)
 | 
					 | 
				
			||||||
func (policy *Policy) IsDirectlyPreview() bool {
 | 
					 | 
				
			||||||
	return policy.Type == "local"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// AfterFind 找到存储策略后的钩子
 | 
					// AfterFind 找到存储策略后的钩子
 | 
				
			||||||
func (policy *Policy) AfterFind() (err error) {
 | 
					func (policy *Policy) AfterFind() (err error) {
 | 
				
			||||||
	// 解析存储策略设置到OptionsSerialized
 | 
						// 解析存储策略设置到OptionsSerialized
 | 
				
			||||||
@ -147,3 +142,8 @@ func (policy *Policy) GenerateFileName(uid uint, origin string) string {
 | 
				
			|||||||
	fileRule = util.Replace(replaceTable, fileRule)
 | 
						fileRule = util.Replace(replaceTable, fileRule)
 | 
				
			||||||
	return 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
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 对文件名进行URLEncode
 | 
				
			||||||
 | 
						fileName, err := url.QueryUnescape(path.Base(dst))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	// 上传文件
 | 
						// 上传文件
 | 
				
			||||||
	resp, err := handler.Client.Request(
 | 
						resp, err := handler.Client.Request(
 | 
				
			||||||
		"POST",
 | 
							"POST",
 | 
				
			||||||
@ -109,7 +114,7 @@ func (handler Handler) Put(ctx context.Context, file io.ReadCloser, dst string,
 | 
				
			|||||||
		request.WithHeader(map[string][]string{
 | 
							request.WithHeader(map[string][]string{
 | 
				
			||||||
			"Authorization": {credential.Token},
 | 
								"Authorization": {credential.Token},
 | 
				
			||||||
			"X-Policy":      {credential.Policy},
 | 
								"X-Policy":      {credential.Policy},
 | 
				
			||||||
			"X-FileName":    {path.Base(dst)},
 | 
								"X-FileName":    {fileName},
 | 
				
			||||||
		}),
 | 
							}),
 | 
				
			||||||
		request.WithContentLength(int64(size)),
 | 
							request.WithContentLength(int64(size)),
 | 
				
			||||||
	).CheckHTTPResponse(200).DecodeResponse()
 | 
						).CheckHTTPResponse(200).DecodeResponse()
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user