Using WordPress’s add_cap method to Allow Contributors to Upload Media is not Working

Try changing current_user_can('contributor') to current_user_can('edit_posts'). According to the Codex, ‘Passing role names to current_user_can() is discouraged as this is not guaranteed to work correctly.’