I'm a little curious why you went this route?  Why not just use the built-in versioning that Confluence does for attachments?  An attachment of the same name will automatically get a new attachment version, and the latest version of the attachment will be used.