spring boot and javascript display image in web browser, broken icon/black box

In my file API setup, I successfully save a file. However, in the service and controller layers, when I attempt to retrieve all files associated with a specific user, JavaScript calls the endpoint but only displays a blank box. There are no visible errors.

So, initially, I stored the file as a byte[]. When I called the endpoint from JavaScript, the backend encoded it into base64. This encoded data is then displayed in a container where multiple files can be organized in rows. Previously, when there was an issue, it showed a broken image icon/blank box.

FileService:
public File uploadFile(Profile profile, MultipartFile file) throws IOException {
        logger.info("FileService - Uploading file for profile ID: {}", profile.getId());

        File uploadedFile = new File();
        uploadedFile.setProfile(profile);
        uploadedFile.setFileName(file.getOriginalFilename());
        uploadedFile.setFileType(file.getContentType());
        uploadedFile.setFileSize(file.getSize());
        uploadedFile.setUploadDate(LocalDate.now());
        uploadedFile.setFileContent(file.getBytes());

        uploadedFile = fileRepository.save(uploadedFile);

        logger.info("FileService - File uploaded successfully. File ID: {}", uploadedFile.getId());

        return uploadedFile;
    }
fileController:
@PostMapping("/upload/{profileId}")
    public ResponseEntity<File> uploadFile(@PathVariable Long profileId, @RequestParam("file") MultipartFile file) {
        logger.info("FileController - Uploading file for profile ID: {}", profileId);

        Optional<Profile> optionalProfile = profileRepository.findById(profileId);
        if (optionalProfile.isPresent()) {
            Profile profile = optionalProfile.get();
            try {
                File uploadedFile = fileService.uploadFile(profile, file); // Delegate to service
                logger.info("FileController - File uploaded successfully for profile ID: {}", profileId);
                return ResponseEntity.status(HttpStatus.CREATED).body(uploadedFile);
            } catch (IOException e) {
                logger.error("FileController - Error uploading file for profile ID: {}", profileId, e);
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
            }
        } else {
            logger.warn("FileController - Profile not found for ID: {}", profileId);
            return ResponseEntity.notFound().build();
        }
    }
Javascript to display file and encode it to base64
function displayFile(file) {
    console.log('File to display:', file);

    const fileContainer = document.getElementById('fileContainer');
    const fileElement = document.createElement('div');
    fileElement.classList.add('file-item');

    // Set background image using base64 encoded string provided by backend
    fileElement.style.backgroundImage = `url('data:${file.fileType};base64,${file.fileContent}')`;
    fileElement.title = file.fileName;

    // Add click event to show file in modal
    fileElement.addEventListener('click', () => showFileInModal(file));

    // Append the file element to the file container
    fileContainer.appendChild(fileElement);
}
css file
.file-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    max-height: calc(100vh - 200px); /* Adjust height as needed */
    overflow-y: auto;
}

.file-item {
    display: inline-block;
    width: 200px;
    height: 200px;
    background-size: cover;
    background-position: center;
    border: 1px solid #ccc;
}

.file-thumbnail {
    max-width: 100%; /* Adjust to fit your container width */
    height: auto;    /* Maintain aspect ratio */
}

.file-details {
    flex: 2;
}
html file where the files are being displayed
 <div class="content mt-4">
      <div class="file-container" id="fileContainer">
          <!-- Files will be dynamically added here -->
      </div>
      <div id="uploadMessage" class="mt-3"></div> <!-- Element for upload status message -->
       <!-- Main content goes here -->
  </div>

I am using google chrome, if that info is needed as well.

outcome on screen:

result of taking the byte file -> base64 encode and display

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật