FYI there is already native support to put uploads in S3 storage, you just need to enable:
So the current Post UI already supports this.
Perhaps you can leverage that if you need further modifications and should simplify your project significantly.
See: Configure an S3 compatible object storage provider for uploads