I have a program that accepts an image and creates a string that links to the image to save in the database.
currently I have the string stored in a state called image1
And I am sending the data to my backend with the following code on the front end
const scheduleEvent = (e) => {
e.preventDefault();
let userData = [
{
image: image1
},
];
axios.post(
"proper-url",
userData
);
console.log(userData) // this returns: 0: {image: "https://i.imgur.com/LnZUdnr.jpg"}
};
And I this is my webhook to capture the data and send it to the database
exports = async function(payload, response) {
if (payload.body) {
const body = EJSON.parse(payload.body.text());
const customerEvents= context.services.get("mongodb-atlas").db("db").collection("events");
const event = {
image: body.image1,
};
return await customerEvents.insertOne(event);
}
return {}
};
However my database entries look like this _id:6229194de167780bd1982029 without the image variable. I know that my code is connecting to the database and adding things to it, but no matter what I do I cannot get it to record the image1 string
In your client code you're sending a field named image, but in your server side you're looking for the field image1. This is undefined, which is why it's not showing up in your database.