img标签转换为file对象

22 阅读1分钟
const imgElement = document.getElementById('previewImage')
                const imgUrl = imgElement.src
                console.log('111this.appCoverFileData', this.appCoverFileData)
                await fetch(imgUrl)
                    .then((response) => response.blob())
                    .then((blob) => {
                        // 在这里,`blob` 是图片的数据
                        // 接下来,你可以将其转换为文件对象
                        const file = new File([blob], 'filename.png', { type: 'image/png' })
                        formData.append('file', file)
                    })