js 圖片網絡地址轉成文件流


 var enclo = row.sceneImg.split(",");
            // 將文件轉為blob對象,再轉為file對象
            enclo.forEach((item) => {
                if (item) {
                    var name =
                        "http://61.153.185.211:8084/LightningDetection/ProjectOriginalRecord/" +
                        item;
                    this.changeBlob(name).then((res) => {
                        var na = name.split("/");
                        const files = new File([res], na[na.length - 1], {
                            type: res.type,
                        });
                        // var Blob = window.URL.createObjectURL(res);
                        this.fileListPng.push(files);
                    });
                }
            });
 // 地址轉文件
        changeBlob(url) {
            return new Promise((resolve) => {
                const xhr = new XMLHttpRequest();
                xhr.open("GET", url, true);
                xhr.responseType = "blob";
                xhr.onload = () => {
                    if (xhr.status === 200) {
                        resolve(xhr.response);
                    }
                };
                xhr.send();
            });
        },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM