Browser not refreshing image when image source URL is changed to URL of the image in the AWS S3 bucket

My react app allows the user to upload photos from their system and facebook (yet to be implemented). After uploading from the system, the URL of the displayed images are object URLs. Upon clicking Save, presigned URLs are requested from the server for each image. The presigned URLs are split to get only the URL portion (uptil .png or .jpg). Then the image source URLs are changed to the presigned URLs. The expectation is that the image refreshes by loading the image from the new image source. But it does not. However, if I right-click on select load image, the image loads. I tried things like cachebreaker, putting the image rendering code in a react component, using onError fallback, unique keys on images. Doesn’t work. Can anyone let me know a workaround. Code is as below.

photopicker.js

import Box from '@mui/material/Box'
import * as React from 'react';
import { useState, useEffect } from "react";
import ReactDOM from "react-dom/client";
import '../../css/styles.css'
import Typography from '@mui/material/Typography';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faRectangleXmark } from "@fortawesome/free-solid-svg-icons";
import { faTrashCan } from "@fortawesome/free-solid-svg-icons";
import { faComputer } from "@fortawesome/free-solid-svg-icons";
import FacebookIcon from '@mui/icons-material/Facebook';
import Icon from '@mui/material/Icon';
import { useRef } from 'react';
import Button from '@mui/material/Button';
// import { Provider } from 'react-redux';
import { store } from '../appstate/store'
// import { useSelector, useDispatch } from 'react-redux'
// import { picArrayAdd, picArrayDel } from '../appstate/photopickerslice';
import axios from 'axios';
import Tooltip from '@mui/material/Tooltip';

export default function PhotoPicker() {
    const inputRef = useRef();
    const openFileDialog = (e) => {
        inputRef.current.value = null;
        inputRef.current.click()
    }
    // const initialImageArrayState = [];
    const [presignedURL, setPresignedURL] = useState('');
    const [imageArray, setImageArray] = useState([]);
    const [displaySaveCancelButton, setDisplaySaveCancelButton] = useState("none");
    const [profilePic, setProfilePic] = useState('');

    useEffect(() => {
        imageArray.length !== 0 ? setDisplaySaveCancelButton("") : setDisplaySaveCancelButton("none")
    })
  
    const inputFilePickerFunc = (e) => {
        // console.log(e.target.files);
        var file = e.target.files;
        var k = Object.keys(file);
        var objStore = [];
        k.forEach(
            (key) => {
                objStore.push(file[k[key]]);
            }
        );

        //Check if file is image
        let pattern = /image/
        objStore.forEach((index) => {
            let text = index.type;
            /* console.log(text); */
            let result = text.match(pattern);
            if (result == null) {
                console.log('invalid file');
                objStore.splice(index, 1)
            }
        })
        //Check image size
        objStore.forEach((index) => {
            let imageSize = index.size;
            /* console.log(text); */
            if (imageSize > 15728640) {
                console.log('file ' + index + ' image is bigger than 15 MB size limit.');
                objStore.splice(index, 1)
            }
        })

        //check image dimensions

        objStore.forEach(
            (item) => {
                var im = new Image();
                im.src = URL.createObjectURL(item);
                im.onload = function () {
                    if (im.width < 400 || im.height < 500) {
                        objStore.splice(item, 1);
                        console.log('dimensions should be minimum 400 x 500 of image ' + item.name)

                    }
                    else {
                        console.log(imageArray);
                        setImageArray(prevState => {
                            return [...prevState, { "imagesource": im.src, "profilepic": "no", "file": item, "inS3": "no" }]
                        }
                        )

                    }
                }
                console.log(imageArray)
            }
        )

    }
    const setImgProfilePic = (e) => {
               setProfilePic(e.currentTarget.id);
        let imageArrayDump = [...imageArray];
        for (let i = 0; i < imageArrayDump.length; i++) {
            if (imageArrayDump[i].profilepic == "yes") {
                imageArrayDump[i].profilepic = "no";
                break;
            }
        }
        for (let k = 0; k < imageArrayDump.length; k++) {
            if (imageArrayDump[k].imagesource == e.currentTarget.id) {
                imageArrayDump[k].profilepic = "yes";
                setImageArray([...imageArrayDump]);
                break;
            }
        }

    }
    function deleteItem(e, item) {
        e.stopPropagation();
        let indexofItemtoBeDeleted;
        let dupArr = imageArray.slice();
        for (let i = 0; i < dupArr.length; i++) {
            if (dupArr[i].imagesource == item) {
                indexofItemtoBeDeleted = i;
                break;
            }
        }
        dupArr.splice(indexofItemtoBeDeleted, 1);
        setImageArray([...dupArr]);
    }
      
   
    function savePics() {  
        //check in the image array the number of items with inS3 = no, and send this number to API
        let presignedURLsRequired = [];
        for (let i = 0; i < imageArray.length; i++) {
            if (imageArray[i].inS3 == "no") {
                presignedURLsRequired.push(imageArray[i].file.type);
            }
        }
        axios.post('/presignedUploadURL', {
            "numberOfPresignedURLsRequired": presignedURLsRequired
        }).then(
            (res) => {
                let imageArrayDump = [...imageArray];
                for (let i = 0; i < imageArrayDump.length; i++) {
                    for (let k = 0; k < res.data.length; k++) {
                        if (imageArrayDump[i].file.type == res.data[k].imageType) {
                            imageArrayDump[i].presignedURL = res.data[k].presignedURL;
                            res.data.splice(k, 1);
                        }
                    }
                }
                console.log(imageArrayDump);
                for (let j = 0; j < imageArrayDump.length; j++) {
                    axios.put(imageArrayDump[j].presignedURL, imageArrayDump[j].file)
                        .then(
                            (res) => {
                                if (res.status == 200) {
                                    imageArrayDump[j].inS3 = "yes";
                                }
                            }

                        )
                        .catch(res => console.log(res));
                }
                for(let l = 0; l < imageArrayDump.length; l++){
                     let newImageSource = imageArrayDump[l].presignedURL.split('?')[0];
                     imageArrayDump[l].imagesource = newImageSource;
                     delete imageArrayDump[l].presignedURL;
                 }
                            
                setImageArray([...imageArrayDump]);
            }
        ).catch(err => console.log(err));

      
    }
    
    return (

        <Box sx={{ border: 1, display: 'flex', flexWrap: 'wrap', width: '50%', margin: 'auto', minWidth: '570px' }}>
            <Box sx={{ display: 'flex', border: 1, borderColor: 'red', width: '100%', flexWrap: 'nowrap' }}>

                <Typography sx={{ border: 1, width: '100%', minHeight: '30px', textAlign: "center" }}>
                    Upload pictures
                </Typography>

                <Icon onClick={() => alert("hi")} sx={{ border: 1, cursor: "pointer" }}>
                    <FontAwesomeIcon icon={faRectangleXmark} />
                </Icon>
            </Box>
            <Box sx={{ border: 1, width: '49.5%', minHeight: '50px', textAlign: "center", cursor: "pointer" }} onClick={openFileDialog}><input ref={inputRef} type="file" multiple onChange={inputFilePickerFunc} style={{ display: 'none' }}></input><Typography>Computer</Typography><Icon><FontAwesomeIcon icon={faComputer} /></Icon></Box>
            <Box sx={{ border: 1, width: '49.5%', minHeight: '50px', textAlign: "center" }}><Typography>Facebook</Typography><Icon sx={{ color: 'blue' }}>FacebookIcon</Icon></Box>

            {

                imageArray.length !== 0 &&
                (
                    imageArray.map(
                        (item, index) => {
                            let itemImgSrc = item.imagesource
                         
                            return (

                                <Tooltip key={`${itemImgSrc}1`} title={profilePic == item.imagesource ? "" : "Set as profile pic"}>
                                    <Box key={`${itemImgSrc}2`} id={item.imagesource} style={{ border: profilePic == item.imagesource ? "2px solid red" : "0px" }} onClick={setImgProfilePic} sx={{ width: '49.5%', height: "150px", position: 'relative', cursor: "pointer" }}><Icon id="icon" key={`${itemImgSrc}3`} sx={{ position: 'absolute', right: '0px', cursor: "pointer", color: 'red' }} onClick={(e) => { deleteItem(e, item.imagesource) }}><FontAwesomeIcon icon={faTrashCan} /></Icon><img src={item.imagesource} id={itemImgSrc} index={index} key={`${itemImgSrc}4`} style={{ width: '100%', height: '100%', objectFit: 'contain' }}></img></Box>
                                </Tooltip>

                            )

                        }
                    )
                )

            }

            <Box sx={{ width: '100%', textAlign: "center", display: displaySaveCancelButton }}><Button variant="contained" sx={{ m: 2 }} onClick={savePics}>Save</Button></Box>
        </Box>
    )
}

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