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