At some point in the process you could do the following:
- Generate attachment ID from URL, like here
- Save attachment ID to custom field value using add_post_meta()
- Retrieve attachment using custom field value later with get_post_meta()
At some point in the process you could do the following: