JSFiddle - React, Tailwind, and code Playground

JavaScript

var uploaderCount = 0;

function AsyncFileUploader(options) {

    // Create an hidden iframe to put form into body of document
    
    var iframeName = "__uploader" + (uploaderCount++);
    
    var $iframe = $("<iframe name='" + iframeName + "'/>")
        .appendTo($(document.body))
        .css({
            height: 0,
            width: 0,
            border: 0
        })
    ;
    
    // When iframe is ready, create form and file input in it
    
    $iframe.load(function() {
        
        var $uploadForm =  $("<form target='" + iframeName + "' action='" + options.postUrl + "' method='post' enctype='multipart/form-data' />")
            .appendTo($iframe)             
            .append($("<input type='file' value='" + options.file + "' />"))
        ;
        
        if (options.selectFile === true) {
             $uploadForm.find("input").click();   
        }
        
    });
    
}

var uploader = new AsyncFileUploader({
    postUrl: "http://127.0.0.1",
    selectFile: true
});