React中的文件上传

const data = new FormData();
        data.append('file', this.fileInput.current.files[0]);  //相当于 input:file 中的name属性
        fetch('http://127.0.0.1:3001/file/upload', {
            method: 'POST',
            body: data
        }).then(response => console.log(response))

 

来源:https://segmentfault.com/a/1190000016824949?utm_source=tag-newest

posted @ 2021-05-12 16:57  浅笑19  阅读(706)  评论(0)    收藏  举报