How to use wp_ajax_set_post_thumbnail?

Assuming you’re looking at calling this via an AJAX style call from your browser, I’d suggest you look at the new WordPress REST API.

Here’s the docs for the endpoint for updating posts. This will allow you to do exactly the same thing with the featured_media parameter, and much more, and is likely much better documented.

https://developer.wordpress.org/rest-api/reference/posts/#update-a-post

EDIT:

Here’s a quick example of using jQuery to do a POST to update the ID of the featured media to 456 on post ID 123. This is a quick example and untested to give you an example of how this works with jQuery, but please reply if you have errors so it can be updated.

    var postID = 123
    var imageID = 456
    var apiURL = "https://yoursite.com/wp-json/wp/v2/posts/"
    var thisPostURL = apiURL + postID
    $.post( thisPostURL, 
            { 'featured_media' : imageID }
          );

EDIT 2:

Not sure if this will get you all the way, but the function to set the featured image when you’re in PHP is set_post_thumbnail

So if you can call your plugin after the image is uploaded, you just need the post ID and the new image ID and you can do this in PHP:

set_post_thumbnail($postId, $imageID);

EDIT 3:

So it’s unclear what you’re trying to do in the PHP you pasted with inserting into the imagepackages table directly, but you need to use wp_insert_attachment to be able to upload an image into WordPress’s media library, and then get an ID which you can use to easily make this image the featured image. If you want to upload your file somewhere else and do something else with it, you should probably still do wp_insert_attachment afterwards, otherwise it won’t be possible to easily use the image in WordPress.

Here’s an example taken from the comments in the previously linked page which shows how to add an image and then use the ID returned to set it as the featured image.

    // Insert the attachment.
    $attach_id = wp_insert_attachment( $attachment, $filename, $parent_post_id );

    // Make sure that this file is included, as         wp_generate_attachment_metadata() depends on it.
    require_once( ABSPATH . 'wp-admin/includes/image.php' );

    // Generate the metadata for the attachment, and update the database record.
    $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
    wp_update_attachment_metadata( $attach_id, $attach_data );

    set_post_thumbnail( $parent_post_id, $attach_id );