antd upload组件自定义上传行为

自定义上传行为,不到服务器,直接浏览器本地获取图片 base 64 进行操作

const customRequest = (options) => {
        const {onSuccess, onError, file, onProgress} = options

        const reader = new FileReader()
        reader.readAsDataURL(file)

        reader.onload = (file) => {
            setFileList([{
                uid: '-1',
                name: 'image.png',
                status: 'done',
                url: file.target.result,
            }])


            let posterTemplateData = JSON.parse(JSON.stringify(_state.posterTemplateData)) as TypeMaterialData
            posterTemplateData.imgSlot[0].src = file.target.result

            _setState(prevState => ({
                ...prevState,
                posterTemplateData,
            }))


        }
    }

                 {fileList.length < 1 && '+ Upload'}

你可能感兴趣的:(antd upload组件自定义上传行为)