這是代碼,明明已經把file賦給body,可是在瀏覽器發送請求時根本沒有requestpayload,后端也看不見數據,請問這是為何?import React, { Component } from 'react';let a=1;class Upload extends Component{ state = { file:null } handleFileClick(e) { this.setState({file: e.target.files[0]}); } handleSubmitClick(e) { console.log(this.state.file); fetch("http://localhost:8080//upload.do",{ method: 'POST', headers:{ 'Access-Control-Allow-Origin':'*', 'Content-Type': 'multipart/form-data;boundary=56423498738365' }, mode: 'cors', body: this.state.file }); } render(){ return ( <div> <input type="file" onChange={this.handleFileClick.bind(this)}/> <input type="button" value="123" onClick={this.handleSubmitClick.bind(this)}/> </div> ); }}export default Upload;
關于fetch api的文件上傳問題,為何請求體里什么內容都沒有
一只名叫tom的貓
2019-03-05 17:23:33