Browse Source

下载模型接口

pull/883/head
liuzx 3 years ago
parent
commit
18039995f7
2 changed files with 33 additions and 12 deletions
  1. +21
    -0
      modules/storage/obs.go
  2. +12
    -12
      routers/api/v1/repo/modelarts.go

+ 21
- 0
modules/storage/obs.go View File

@@ -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


+ 12
- 12
routers/api/v1/repo/modelarts.go View File

@@ -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)


Loading…
Cancel
Save