【发布时间】:2018-12-14 20:26:20
【问题描述】:
我正在尝试将文件上传到cloudinary。这是我的 react 组件
的一部分...
addItem() {
...
let file = this.fileInput.value;
keywords !== "" && this.props.onAddItem(keywords, place, image);
...
}
render() {
return (
....
<Input
type="file"
innerRef={(input) => {this.fileInput = input}}
name="image"
id="image"
placeholder=""/>
)
}
这是动作文件:
export function onAddItem(keywords, place, file, id, isChangebale = false) {
return (dispatch) => {
axios.all([
axios.post('https://api.cloudinary.com/v1_1/myservername/image/upload',
{upload_preset: "mypresetname", file: file}),
axios.post('http://localhost:3001/api/items/', { keywords, place, id, isChangebale })
])
.then(axios.spread((cloudinaryRes, localRes) => {
console.log(cloudinaryRes, localRes);
}))
我收到错误 xhr.js:178 POST https://api.cloudinary.com/v1_1/testovich/image/upload 400 (Bad Request) 和响应标头 "X-Cld-Error: Unsupported source URL: C:\fakepath\2017-12-07_19-06-445.png"
当我使用postman 进行测试时,我得到了正确的响应。
所以看起来我在将文件从 rect 组件传递到操作文件时做错了。如何将正确的路径/文件传递给 cloudinary?
【问题讨论】:
标签: reactjs express axios cloudinary