尝试使用axios.put将已上传到AWS的图像放入React应用程序的MongoDB数据库中时出现此错误。一切正常,直到我尝试从useselector插入用户ID来将图像与当前用户个人资料图像相关联。可以根据需要上传更多代码
import React, { Component } from 'react';
import axios from 'axios';
import $ from 'jquery';
import API from '../../utils/API'
import { useSelector } from "react-redux";
class ImageUpload extends Component {constructor( props ) {
...
} else {
// Success
const user = useSelector(state => state.auth.currentUser);
let fileName = response.data;
console.log( 'fileName', fileName );
this.ocShowAlert( 'File Uploaded', '#3089cf' );
const imageName = fileName.image;
const imageLocation = fileName.location;
const imageData = {
"profileimage": [
{
"imagename": imageName
},
{
"imagelocation": imageLocation
}
]
}
API.editUser(user._id, imageData)
.then(() => {
console.log("Yo you updated the profile image");
console.log(user);
})
}
}
}).catch( ( error ) => {
// If another error
this.ocShowAlert( error, 'red' );
});
} else {
// if file not selected throw error
this.ocShowAlert( 'Please upload file', 'red' );
}
}