how do prevent wordpress from creating permalinks for media files

In a plugin or in your functions.php file put this :

if ( !function_exists( 'xxx_remove_attachment_permalink' ) ) {
    function xxx_remove_attachment_permalink( $rules ) {
        foreach ( $rules as $regex => $query ) {
            if ( strpos( $regex, 'attachment' ) || strpos( $query, 'attachment' ) ) {
                unset( $rules[ $regex ] );
            }
        }

        return $rules;
    }
    add_filter( 'rewrite_rules_array', 'xxx_remove_attachment_permalink' );
}

if ( !function_exists( 'xxx_remove_attachment_link' ) ) {
    function xxx_remove_attachment_link( $link ) {
        return;
    }
    add_filter( 'attachment_link', 'xxx_remove_attachment_link' );
}