@Carol Sharing code snippet
// Read the file into a byte array
byte[] fileBytes = Files.readAllBytes(filePath);
// Set headers
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
// Create the HTTP entity
HttpEntity<byte[]> entity = new HttpEntity<>(fileBytes, headers);
// Execute the PUT request
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.exchange(
signedUrl,
HttpMethod.PUT,
entity,
String.class
);
if (response.getStatusCode() == HttpStatus.OK) {
return "Upload successful!";
} else {
return "Upload failed: " + response.getStatusCode();
}