|
35 | 35 |
|
36 | 36 | import java.io.File; |
37 | 37 | import java.io.IOException; |
| 38 | +import java.nio.file.Path; |
| 39 | +import java.nio.file.Paths; |
38 | 40 | import java.time.Instant; |
39 | 41 | import java.util.ArrayList; |
40 | 42 | import java.util.Date; |
@@ -86,7 +88,7 @@ public StageUploadResult uploadFileToStage(String localDirOrFilePath) throws Exc |
86 | 88 | File file = new File(localFilePath); |
87 | 89 | long fileStartTime = System.currentTimeMillis(); |
88 | 90 | try { |
89 | | - uploadLocalFileToStage(localFilePath); |
| 91 | + uploadLocalFileToStage(localFilePath, localDirOrFilePath); |
90 | 92 | long bytes = processedBytes.addAndGet(file.length()); |
91 | 93 | long elapsed = System.currentTimeMillis() - fileStartTime; |
92 | 94 | double percent = totalBytes == 0 ? 100.0 : (bytes * 100.0 / totalBytes); |
@@ -145,10 +147,19 @@ private String convertDirPath(String inputPath) { |
145 | 147 | return inputPath + "/"; |
146 | 148 | } |
147 | 149 |
|
148 | | - private String uploadLocalFileToStage(String localFilePath) throws Exception { |
| 150 | + private String uploadLocalFileToStage(String localFilePath, String rootPath) throws Exception { |
149 | 151 | File file = new File(localFilePath); |
150 | | - String fileName = file.getName(); |
151 | | - String remoteFilePath = applyStageResponse.getUploadPath() + fileName; |
| 152 | + Path filePath = file.toPath().toAbsolutePath(); |
| 153 | + Path root = Paths.get(rootPath).toAbsolutePath(); |
| 154 | + |
| 155 | + String relativePath; |
| 156 | + if (root.toFile().isFile()) { |
| 157 | + relativePath = file.getName(); |
| 158 | + } else { |
| 159 | + relativePath = root.relativize(filePath).toString().replace("\\", "/"); |
| 160 | + } |
| 161 | + |
| 162 | + String remoteFilePath = applyStageResponse.getUploadPath() + relativePath; |
152 | 163 | putObject(file, remoteFilePath); |
153 | 164 | return remoteFilePath; |
154 | 165 | } |
|
0 commit comments