LovelyGelina Since offline mode works, it's possible the issue here is OneDrive or your antivirus. The first question is whether your Sims 4 user folder is inside the OneDrive folder; here's how to find out:
https://sims4.crinrict.com/eng/2018/07/how-to-find-your-user-folder/
If that's not the issue, and you use a third-party antivirus, try temporarily disabling real-time scanning while you play. As long as you don't do anything else while testing, your computer should be safe.
If neither helps, try playing with your computer online but with Online Social Access disabled within Sims 4. The setting is under Options > Game Options > Other. This would cut off your access to the Gallery but otherwise not impact the game itself.