From 1dac293b9beeb192570392fde0fabd018bcb4a19 Mon Sep 17 00:00:00 2001 From: wangjian Date: Tue, 4 Apr 2023 18:22:36 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/file.go | 1 + mq/index.go | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/model/file.go b/model/file.go index 4aeb149..c6034bc 100644 --- a/model/file.go +++ b/model/file.go @@ -5,6 +5,7 @@ type FileManager struct { FileName string `xorm:"VARCHAR(200)" json:"fileName"` //文件名 AccessUrl string `xorm:"VARCHAR(400)" json:"url"` //访问路径 Scene string `xorm:"VARCHAR(40)" json:"scene"` //应用场景,0 : 其他, 1: 道路; 2: 桥梁; 3:隧道; 4: 边坡 + DataType int `xorm:"TINYINT index default 0" json:"dataType"` //数据类型,1:数据集;2:病害库;3:应用;0:其他 DatasetId int64 `xorm:"INT(11) index default 0" json:"datasetId"` //数据集 FileSize int64 `xorm:"BIGINT" json:"fileSize"` //文件大小 FileMd5 string `xorm:"VARCHAR(64)" json:"fileMd5"` //文件MD5 diff --git a/mq/index.go b/mq/index.go index 1cfa8c9..6c551b5 100644 --- a/mq/index.go +++ b/mq/index.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/minio/minio-go/v7" "os" + "path" "time" "git.hpds.cc/pavement/hpds_node" @@ -120,12 +121,12 @@ func handler(data []byte) (byte, []byte) { Error("错误信息", zap.Error(err)) } fileReader := bytes.NewReader(fileContent) - info, err := global.MinioClient.PutObject(context.Background(), global.Cfg.Minio.Bucket, fmt.Sprintf("%s%s", model.GetDatasetScene(dt.CategoryId), payload["filePath"].(string)), fileReader, int64(payload["fileSize"].(float64)), minio.PutObjectOptions{ContentType: "application/octet-stream"}) + info, err := global.MinioClient.PutObject(context.Background(), global.Cfg.Minio.Bucket, path.Join(model.GetDatasetScene(dt.CategoryId), dt.StoreName, payload["filePath"].(string)), fileReader, int64(payload["fileSize"].(float64)), minio.PutObjectOptions{ContentType: "application/octet-stream"}) if err != nil { global.Logger.With(zap.String("文件名称", payload["filePath"].(string))).With(zap.Int64("文件大小", int64(payload["fileSize"].(float64)))). Error("错误信息", zap.Error(err)) } - accessUrl := fmt.Sprintf("%s://%s/%s/%s%s", global.Cfg.Minio.Protocol, global.Cfg.Minio.Endpoint, global.Cfg.Minio.Bucket, model.GetDatasetScene(dt.CategoryId), payload["filePath"].(string)) + accessUrl := fmt.Sprintf("%s://%s", global.Cfg.Minio.Protocol, path.Join(global.Cfg.Minio.Endpoint, global.Cfg.Minio.Bucket, info.Key)) global.Logger.With(zap.String("文件名称", payload["filePath"].(string))).With(zap.String("访问路径", accessUrl)). With(zap.Any("返回数据", info)).Info("文件上传到minio") @@ -133,6 +134,7 @@ func handler(data []byte) (byte, []byte) { fm.FileName = payload["fileName"].(string) fm.AccessUrl = accessUrl fm.Scene = fmt.Sprintf("%d", dt.CategoryId) + fm.DataType = int(payload["dataType"].(float64)) fm.DatasetId = dt.DatasetId fm.FileSize = int64(payload["fileSize"].(float64)) fm.FileMd5 = payload["fileMd5"].(string)