【发布时间】:2019-07-05 08:01:50
【问题描述】:
我正在尝试为从我的 React 应用上传的图片设置“Cloudinary”。
我的提交函数一直响应:“Bad Gateway 502”和“SyntaxError: Unexpected end of input”。
我假设我的标题有问题,但我找不到问题...
handleFileSelect = (e) => {
this.formValid()
this.setState({
picture: e.target.files[0] })
}
submit(){
const CLOUDINARY_URL=
"https://api.cloudinary.com/v1_1/dvz27u2gu/image/upload"
const CLOUDINARY_UPLOAD_PRESET= "jshvp3nh"
const obj = Object.assign({}, this.state);
const formData = new FormData();
formData.append("file", obj.picture);
formData.append("upload_preset", CLOUDINARY_UPLOAD_PRESET);
fetch(CLOUDINARY_URL,{
mode: 'no-cors',
method:'post',
headers: { "Content-Type": "application/x-www-form-urlencoded"},
body:formData,
})
.then((res)=>{return res.json()})
.then(data=>console.log(data))
.catch(err=>console.log(err));
}
【问题讨论】:
-
那个具体问题四年前就解决了,所以如果是服务器端的问题,可能就不完全一样了
标签: javascript reactjs rest cloudinary