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)