Skip to content

Commit

Permalink
Fix: OSS SDK will encode all object key (#694)
Browse files Browse the repository at this point in the history
(cherry picked from commit b9cd82b)
  • Loading branch information
ihipop authored Mar 17, 2021
1 parent 170f227 commit 270f617
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ version.lock
*.ini
conf/conf.ini
/statik/
/vendor/
11 changes: 7 additions & 4 deletions pkg/filesystem/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package filesystem

import (
"context"
"io"

model "github.com/cloudreve/Cloudreve/v3/models"
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/fsctx"
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/response"
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
"github.com/cloudreve/Cloudreve/v3/pkg/util"
"github.com/juju/ratelimit"
"io"
"net/url"
)

/* ============
Expand Down Expand Up @@ -288,8 +288,11 @@ func (fs *FileSystem) signURL(ctx context.Context, file *model.File, ttl int64,
if err != nil {
return "", serializer.NewError(serializer.CodeNotSet, "无法获取外链", err)
}

return source, nil
// 阿里云的 golang SDK 会把整个object KEY也编码 临时解决方案是清空`RawPath`让golang的`url.EscapedPath`修正这个问题
// https://github.com/cloudreve/Cloudreve/issues/677 https://github.com/aliyun/aliyun-oss-go-sdk/blob/6f7e8f88c64181cc2d86d8bd46090b68851e645a/oss/conn.go#L767
sourceUrl, _ := url.Parse(source)
sourceUrl.RawPath = ""
return sourceUrl.String(), nil
}

// ResetFileIfNotExist 重设当前目标文件为 path,如果当前目标为空
Expand Down

0 comments on commit 270f617

Please sign in to comment.