Users uploaded image and matching an id or taxonomy

You can still use the media library and either reference the attachment’s ID or add a postmeta to the attachment containing your id.

You could even make this a bit easier by using a custom taxonomy instead of custom field. Add your numbers as terms to that taxonomy. Also register the taxonomy to apply to attachments. Then write a bit of code that whenever the post has (a) term(s) in that taxonomy finds the attachments that also have a the same term(s) in that taxonomy. This would even allow you to have both, multiple of your numbers for a post and multiple images per number, leading to all kinds of possible combinations.