using bff

This commit is contained in:
pratik
2025-10-22 14:39:46 -05:00
parent 05d452c250
commit 4e24d93a5a
2 changed files with 51 additions and 4 deletions

View File

@@ -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"
fi
# Send metadata as query params and chunk file as raw binary body
# This works with Java proxy that forwards body as-is
# Base64 encode the chunk so Java proxy can handle it as text/String
# 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" \
-H "Content-Type: application/octet-stream" \
--data-binary "@$chunk_file")
-H "Content-Type: text/plain" \
-H "X-Chunk-Encoding: base64" \
-d "$CHUNK_BASE64")
if [ "$DEBUG_MODE" = "true" ]; then
echo "DEBUG: Chunk response: $RESPONSE"

View File

@@ -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")
public ResponseEntity<DeploymentStatus> finalizeUpload(
@RequestParam("uploadSessionId") String uploadSessionId,