Upload media (image) and set the category

First of all, if you want to apply categories to Attachments, you have to enable categories for the attachment.

You can do this by using the register_taxonomy_for_object_type() function. In your plugin file or theme functions file, add the following:

function wp_add_categories_to_attachments() {
    register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'wp_add_categories_to_attachments' );