Redirect Function Prevents Images from Showing in Front-end Media Uploader

For anyone who this might help, I found a working solution. Redirecting is working and users can see their images at the front-end WP Media Uploader.

function my_noAdminAccess(){
if ( is_admin() && ! current_user_can( 'delete_others_posts' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
    if( wp_get_referer() ){
        wp_safe_redirect( wp_get_referer() );
        }
    else{
        wp_safe_redirect( site_url("https://wordpress.stackexchange.com/") );
        }
    exit;
    }
}
add_action( 'admin_init', 'my_noAdminAccess', 100 );