Fs.createReadStream不是函数
这是我的代码片段:
import axios from 'axios';
import FormData from 'form-data';
var fs = require('fs');
submitCareerForm(e){
e.preventDefault();
let formData = new FormData(); //formdata object
formData.append('first_name',this.state.fname);
formData.append('last_name',this.state.lname);
formData.append('cv', fs.createReadStream(this.state.cv));
formData.append('email', this.state.email);
formData.append('phone',this.state.phone);
formData.append('details',this.state.details);
formData.append('preferred_contact',this.state.preferredContact);
console.log('resume ****** ',this.state.cv)
let config = {
method: 'post',
url: 'https://sbtsbackend.azurewebsites.net/users/carrers',
data : formData
};
axios(config)
.then(resData => {
console.log('result data ******** ',resData)
if(resData.data.statusCode == 200){
alert(resData.data.message);
}
this.setState({
fname: '',
lname: '',
cv: '',
address: '',
city: '',
state: '',
postalcode: '',
country: '',
phone: '',
email: '',
details: '',
});
})
.catch((error)=>{
console.log('error ******* ',error)
})
}
我要上传文档类型为文档、文档或pdf。对于邮递员,API运行得很好。如何在此实施?
这是我收到的错误:
解决方案
Node.js的fs
模块仅适用于服务器端应用程序。当您在客户端应用程序的Web浏览器中使用它时,它将引发错误。
相关文章