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

阿里云OSS下载时无法获取真实文件名 #1117

Closed
z-my-cn opened this issue Jan 22, 2022 · 8 comments
Closed

阿里云OSS下载时无法获取真实文件名 #1117

z-my-cn opened this issue Jan 22, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@z-my-cn
Copy link

z-my-cn commented Jan 22, 2022

环境

阿里云OSS:公有读私有写
Cloudreve:3.4.2

问题复现

如下,polr.zip为原上传文件,uploads_2022_Ab4xwize_polr.zip为上传后下载文件
uploads_2022_Ab4xwize为配置的存储路径uploads/{year}/{randomkey8}
image
通过外链获取如下:
https://z-my.oss-cn-hangzhou.aliyuncs.com/uploads%2F2022%2FAb4xwize%2Fpolr.zip?Expires=1642852526

问题对比

同配置下七牛云正常 阿里云异常

@z-my-cn
Copy link
Author

z-my-cn commented Jan 24, 2022

目测应该是获取下载的时候将字符“/”转换成了“%2F”,希望可以调整一下,毕竟总不能把所有文件放在根目录下。

@lsCoding666
Copy link

试试改下file.go里面的GetDownloadURL方法,将返回的source中的%2f替换为/试试?

@z-my-cn
Copy link
Author

z-my-cn commented Feb 8, 2022

这应该是一个好办法,可惜我对go并不是很熟悉,还是希望可以尽快修复

@lsCoding666
Copy link

lsCoding666 commented Feb 9, 2022

我代码做了一些调整 不知道能不能解决你的问题
/pkg/filesystem/driver/oss/handler.go
原本的代码长这样

return finalURL.String(), nil

改后的

func (handler Driver) signSourceURL(ctx context.Context, path string, ttl int64, options []oss.Option) (string, error) {
//省略
	decodedValue, err := url.QueryUnescape(finalURL.String())
	if err != nil {
		return "", nil
	}
	//return finalURL.String(), nil
	return decodedValue, nil

二进制文件已上传至https://pan.c34.pw/s/lbf4

测试的时候备份原来的二进制文件和数据库

@z-my-cn
Copy link
Author

z-my-cn commented Feb 9, 2022

完美解决问题,非常感谢您提供解决办法

我代码做了一些调整 不知道能不能解决你的问题 /pkg/filesystem/driver/oss/handler.go 原本的代码长这样

return finalURL.String(), nil

改后的

func (handler Driver) signSourceURL(ctx context.Context, path string, ttl int64, options []oss.Option) (string, error) {
//省略
	decodedValue, err := url.QueryUnescape(finalURL.String())
	if err != nil {
		return "", nil
	}
	//return finalURL.String(), nil
	return decodedValue, nil

二进制文件已上传至https://pan.c34.pw/s/lbf4

测试的时候备份原来的二进制文件和数据库

@HFO4 HFO4 added the bug Something isn't working label Feb 23, 2022
@hatiwowo
Copy link

使用您的办法后,外链变成为https://haticloud.oss-cn-shanghai.aliyuncs.com/2/阿里云/eye.png?Expires=1647412680
使用阿里云默认的oss browser,同一文件获取到的连接为https://haticloud.oss-cn-shanghai.aliyuncs.com/2/%E9%98%BF%E9%87%8C%E4%BA%91/eye.png
路径同样做一个encodeURIComponent会不会更好一点

@lsCoding666

@linfun486
Copy link

linfun486 commented Mar 16, 2022

@hatiwowo 试试看

func (handler Driver) signSourceURL(ct...
省略...

	if handler.Policy.BaseURL != "" {
		cdnURL, err := url.Parse(handler.Policy.BaseURL)
		if err != nil {
			return "", err
		}
		finalURL.Host = cdnURL.Host
		finalURL.Scheme = cdnURL.Scheme
	}

	return decodeUrl(finalURL.String()) //替换方法
}

//转正确的url路径 增加的方法
func decodeUrl(urlString string) (ret string, err error) {
	ret, err = url.QueryUnescape(urlString)
	if err != nil {
		return
	}
	ss := strings.Split(ret, "/")
	for i, item := range ss {
		ss[i] = url.QueryEscape(item)
	}
	ret = strings.Join(ss, "/")
	return
}

@HFO4
Copy link
Member

HFO4 commented Mar 18, 2022

oss-golang-sdk 的问题,暂时无法解决,参考 aliyun/aliyun-oss-go-sdk#212

@HFO4 HFO4 closed this as completed Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants