From 18039995f7435a79443f82b04322bb5ef22e2731 Mon Sep 17 00:00:00 2001 From: liuzx Date: Wed, 17 Nov 2021 15:41:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=A8=A1=E5=9E=8B=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/storage/obs.go | 21 +++++++++++++++++++++ routers/api/v1/repo/modelarts.go | 24 ++++++++++++------------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/modules/storage/obs.go b/modules/storage/obs.go index 3a7277c41..56794fd96 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -394,6 +394,27 @@ func GetObsCreateSignedUrl(jobName, parentDir, fileName string) (string, error) return output.SignedUrl, nil } +func GetObsCreateVersionSignedUrl(jobName, parentDir, fileName string, VersionOutputPath string) (string, error) { + input := &obs.CreateSignedUrlInput{} + input.Bucket = setting.Bucket + input.Key = strings.TrimPrefix(path.Join(setting.TrainJobModelPath, jobName, setting.OutPutPath, VersionOutputPath, parentDir, fileName), "/") + + input.Expires = 60 * 60 + input.Method = obs.HttpMethodGet + + reqParams := make(map[string]string) + fileName = url.QueryEscape(fileName) + reqParams["response-content-disposition"] = "attachment; filename=\"" + fileName + "\"" + input.QueryParams = reqParams + output, err := ObsCli.CreateSignedUrl(input) + if err != nil { + log.Error("CreateSignedUrl failed:", err.Error()) + return "", err + } + + return output.SignedUrl, nil +} + func ObsGetPreSignedUrl(uuid, fileName string) (string, error) { input := &obs.CreateSignedUrlInput{} input.Method = obs.HttpMethodGet diff --git a/routers/api/v1/repo/modelarts.go b/routers/api/v1/repo/modelarts.go index d8824b19e..ba4015d3b 100755 --- a/routers/api/v1/repo/modelarts.go +++ b/routers/api/v1/repo/modelarts.go @@ -339,18 +339,18 @@ func ModelDownload(ctx *context.APIContext) { err error ) - // var jobID = ctx.Params(":jobid") - // var versionName = ctx.Query("version_name") - // parentDir := ctx.Query("parentDir") - // task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName) - // if err != nil { - // log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error()) - // return - // } - parentDir := ctx.Query("parentDir") - fileName := ctx.Query("fileName") - jobName := ctx.Query("jobName") - url, err := storage.GetObsCreateSignedUrl(jobName, parentDir, fileName) + var jobID = ctx.Params(":jobid") + versionName := ctx.Query("version_name") + parentDir := ctx.Query("parent_dir") + fileName := ctx.Query("file_name") + task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName) + if err != nil { + log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error()) + return + } + VersionOutputPath := "V" + strconv.Itoa(task.TotalVersionCount) + + url, err := storage.GetObsCreateVersionSignedUrl(task.JobName, parentDir, fileName, VersionOutputPath) if err != nil { log.Error("GetObsCreateSignedUrl failed: %v", err.Error(), ctx.Data["msgID"]) ctx.ServerError("GetObsCreateSignedUrl", err)