<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />
    <title>聚合图床测试</title>
</head>

<body>
    
</body>

</html>
let bedVendor = [
    {
        url: "https://bit.baidu.com/upload/fileUpload",
        name: "百度(技术学院)",
        maxSize: 1024 * 1024 * 5,
        method: "POST",
        field: "file",
        dataHandle: function (data) {
            data = JSON.parse(data);
            if (data.status == "SUCCESS" && data.data) {
                data.url = "https://bit-images.bj.bcebos.com/bit-new/" + data.data;
            }
            return data;
        }
    },
    {
        url: "https://iask.sina.com.cn/question/ajax/fileupload",
        name: "新浪(爱问)",
        maxSize: 1024 * 1024 * 5,
        method: "POST",
        field: "wenwoImage",
        dataHandle: function (data) {
            data = JSON.parse(data);
            if (data.id) {
                data.url = "https://pic.iask.cn/fimg/" + data.id + ".jpg";
            }
            return data;
        }
    }
];

var sebv = document.createElement("select");
bedVendor.forEach(v => {
    var op = new Option(v.name, v.url);
    sebv.appendChild(op);
})

var txtup = document.createElement("input");
txtup.type = "file";
txtup.onchange = function () {
    var file = this.files[0];
    if (file) {
        var vendor = bedVendor.find(x => x.url == sebv.value);
        var fd = new FormData();
        fd.append(vendor.field, file);
        fetch(vendor.url, {
            method: vendor.method,
            body: fd
        }).then(x => x.text()).then(res => {
            console.log(res)
            console.log(vendor.dataHandle(res))
        })
    }
}

document.body.appendChild(sebv);
document.body.appendChild(txtup);