using bff
This commit is contained in:
@@ -211,11 +211,14 @@ upload_file_in_chunks() {
|
|||||||
echo "DEBUG: Uploading chunk to: $API_BASE/upload/chunk?uploadSessionId=$SESSION_ID&fileType=$file_type&chunkIndex=$chunk_index&totalChunks=$total_chunks&fileName=$file_name"
|
echo "DEBUG: Uploading chunk to: $API_BASE/upload/chunk?uploadSessionId=$SESSION_ID&fileType=$file_type&chunkIndex=$chunk_index&totalChunks=$total_chunks&fileName=$file_name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Send metadata as query params and chunk file as raw binary body
|
# Base64 encode the chunk so Java proxy can handle it as text/String
|
||||||
# This works with Java proxy that forwards body as-is
|
# This prevents corruption when proxy reads binary data as String
|
||||||
|
CHUNK_BASE64=$(base64 < "$chunk_file")
|
||||||
|
|
||||||
RESPONSE=$(curl -s -X POST "$API_BASE/upload/chunk?uploadSessionId=$SESSION_ID&fileType=$file_type&chunkIndex=$chunk_index&totalChunks=$total_chunks&fileName=$file_name" \
|
RESPONSE=$(curl -s -X POST "$API_BASE/upload/chunk?uploadSessionId=$SESSION_ID&fileType=$file_type&chunkIndex=$chunk_index&totalChunks=$total_chunks&fileName=$file_name" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: text/plain" \
|
||||||
--data-binary "@$chunk_file")
|
-H "X-Chunk-Encoding: base64" \
|
||||||
|
-d "$CHUNK_BASE64")
|
||||||
|
|
||||||
if [ "$DEBUG_MODE" = "true" ]; then
|
if [ "$DEBUG_MODE" = "true" ]; then
|
||||||
echo "DEBUG: Chunk response: $RESPONSE"
|
echo "DEBUG: Chunk response: $RESPONSE"
|
||||||
|
|||||||
@@ -215,6 +215,50 @@ public class CfDeployController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/upload/chunk", consumes = "text/plain")
|
||||||
|
public ResponseEntity<ChunkUploadResponse> uploadChunkBase64(
|
||||||
|
@RequestParam("uploadSessionId") String uploadSessionId,
|
||||||
|
@RequestParam("fileType") String fileType,
|
||||||
|
@RequestParam("chunkIndex") Integer chunkIndex,
|
||||||
|
@RequestParam("totalChunks") Integer totalChunks,
|
||||||
|
@RequestParam(value = "fileName", required = false) String fileName,
|
||||||
|
@RequestHeader(value = "X-Chunk-Encoding", required = false) String encoding,
|
||||||
|
@RequestBody String chunkDataBase64) {
|
||||||
|
try {
|
||||||
|
log.debug("Receiving base64 chunk {}/{} for session: {}, fileType: {}",
|
||||||
|
chunkIndex + 1, totalChunks, uploadSessionId, fileType);
|
||||||
|
|
||||||
|
// Validate file type
|
||||||
|
if (!fileType.equals("jarFile") && !fileType.equals("manifest")) {
|
||||||
|
throw new IllegalArgumentException("Invalid file type. Must be 'jarFile' or 'manifest'");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode base64 to binary
|
||||||
|
byte[] chunkData;
|
||||||
|
if ("base64".equalsIgnoreCase(encoding)) {
|
||||||
|
chunkData = java.util.Base64.getDecoder().decode(chunkDataBase64);
|
||||||
|
log.debug("Decoded base64 chunk: {} chars -> {} bytes", chunkDataBase64.length(), chunkData.length);
|
||||||
|
} else {
|
||||||
|
// Fallback: treat as raw bytes from string
|
||||||
|
chunkData = chunkDataBase64.getBytes(java.nio.charset.StandardCharsets.ISO_8859_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
chunkedUploadService.uploadChunkRaw(uploadSessionId, fileType, fileName,
|
||||||
|
chunkIndex, totalChunks, chunkData);
|
||||||
|
|
||||||
|
var session = chunkedUploadService.getSession(uploadSessionId);
|
||||||
|
var fileState = session.getFileStates().get(fileType);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(ChunkUploadResponse.success(
|
||||||
|
uploadSessionId, fileType, chunkIndex, totalChunks,
|
||||||
|
fileState.getReceivedChunkCount()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error uploading base64 chunk", e);
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||||
|
.body(ChunkUploadResponse.failure("Failed to upload chunk: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/upload/finalize")
|
@PostMapping("/upload/finalize")
|
||||||
public ResponseEntity<DeploymentStatus> finalizeUpload(
|
public ResponseEntity<DeploymentStatus> finalizeUpload(
|
||||||
@RequestParam("uploadSessionId") String uploadSessionId,
|
@RequestParam("uploadSessionId") String uploadSessionId,
|
||||||
|
|||||||
Reference in New Issue
Block a user