I created a custom product builder where you can enter your details and they are sent along with the product order. All fields have a name=“properties” attribute. I have a field to upload a picture and it sends it along with the order.
Now the task is to validate the fields before adding a product to the cart, so I threw e.preventDefault() on the add to cart button and then send the product by Ajax via /cart/add.js. But the problem is that the picture is not sent this way. How can I send a photo via /cart/add.js so that it appears in the order in the admin panel?
Below is my submission code. As I understand it, when adding a photo it converts it . And changes the name. But when I send it custom, it adds the wrong image and does not send it. Is it possible to fix it?

const productFormBtn = document.querySelector(
".content-builder__sidebar form .product-form__submit"
);
const cardForm = document.querySelector(".content-builder__sidebar form");
productFormBtn.addEventListener("click", (e) => {
e.preventDefault();
const formData = new FormData(cardForm);
const xhr = new XMLHttpRequest();
xhr.open("POST", "/cart/add.js", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.responseType = "json";
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
console.log("Success:", xhr.response);
else {
console.error("Error:", xhr.status, xhr.statusText);
}
};
xhr.onerror = function () {
console.error("Network error");
};
xhr.send(new URLSearchParams(formData));
});
