From 4b5e7fb7f99f461588e106b779c08a737aab9fa8 Mon Sep 17 00:00:00 2001 From: zacYL Date: Wed, 19 Jul 2023 16:00:02 +0800 Subject: [PATCH] =?UTF-8?q?bug:=20=E5=88=A0=E9=99=A4=E5=88=86=E5=8F=91?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E5=AD=98=E6=94=BE=E7=9A=84=E6=96=87=E4=BB=B6?= =?UTF-8?q?=20#972?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../artifact/resolve/file/ArtifactFileFactory.kt | 15 +++++++++++++++ .../controller/api/BlobReplicaController.kt | 6 +----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/resolve/file/ArtifactFileFactory.kt b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/resolve/file/ArtifactFileFactory.kt index 05b668288a..127d185dd6 100644 --- a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/resolve/file/ArtifactFileFactory.kt +++ b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/resolve/file/ArtifactFileFactory.kt @@ -28,6 +28,7 @@ package com.tencent.bkrepo.common.artifact.resolve.file import com.tencent.bkrepo.common.artifact.api.ArtifactFile +import com.tencent.bkrepo.common.artifact.api.toArtifactFile import com.tencent.bkrepo.common.artifact.repository.context.ArtifactContextHolder import com.tencent.bkrepo.common.artifact.resolve.file.bksync.BkSyncArtifactFile import com.tencent.bkrepo.common.artifact.resolve.file.chunk.ChunkedArtifactFile @@ -43,6 +44,7 @@ import org.springframework.stereotype.Component import org.springframework.web.context.request.RequestAttributes.SCOPE_REQUEST import org.springframework.web.context.request.RequestContextHolder import org.springframework.web.multipart.MultipartFile +import java.io.File import java.io.InputStream /** @@ -131,6 +133,19 @@ class ArtifactFileFactory( } } + /** + * 通过表单文件构造artifact file,存放临时目录 + * @param multipartFile 表单文件 + * @param filePath 文件临时存储路径 + */ + fun build(file: MultipartFile, filePath: String): ArtifactFile { + val artifactFile = File(filePath) + file.transferTo(artifactFile) + return artifactFile.toArtifactFile().apply { + track(this) + } + } + /** * 获取当前仓库的存储凭证 */ diff --git a/src/backend/replication/biz-replication/src/main/kotlin/com/tencent/bkrepo/replication/controller/api/BlobReplicaController.kt b/src/backend/replication/biz-replication/src/main/kotlin/com/tencent/bkrepo/replication/controller/api/BlobReplicaController.kt index 84b7e20ae3..f8fff4a703 100644 --- a/src/backend/replication/biz-replication/src/main/kotlin/com/tencent/bkrepo/replication/controller/api/BlobReplicaController.kt +++ b/src/backend/replication/biz-replication/src/main/kotlin/com/tencent/bkrepo/replication/controller/api/BlobReplicaController.kt @@ -31,7 +31,6 @@ import com.tencent.bkrepo.common.api.exception.ErrorCodeException import com.tencent.bkrepo.common.api.exception.NotFoundException import com.tencent.bkrepo.common.api.pojo.Response import com.tencent.bkrepo.common.artifact.api.ArtifactFile -import com.tencent.bkrepo.common.artifact.api.toArtifactFile import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode import com.tencent.bkrepo.common.artifact.resolve.file.ArtifactFileFactory import com.tencent.bkrepo.common.security.permission.Principal @@ -59,7 +58,6 @@ import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RequestPart import org.springframework.web.bind.annotation.RestController import org.springframework.web.multipart.MultipartFile -import java.io.File /** * blob数据同步接口 @@ -110,9 +108,7 @@ class BlobReplicaController( ArtifactFileFactory.build(file, credentials) } else { val filepath: String = credentials.upload.location + "/" + fileName - val artifactFile = File(filepath) - file.transferTo(artifactFile) - artifactFile.toArtifactFile() + ArtifactFileFactory.build(file, filepath) } }