I am trying to send a post request to a spring boot server via axios.post.
Here is my code snippet
export function createSingleProduct(productData) {
const formData = new FormData();
const data = {
catergoryName: productData[0].product.categoryName,
productName: productData[0].product.productName,
serialNumber: productData[0].product.serialNumber,
purchasePrice: parseInt(productData[0].product.purchasePrice),
purchaseDate: productData[0].product.purchaseDate,
warrantyInYears: parseInt(productData[0].product.warrantyInYears),
warrantyExpiryDate: productData[0].product.warrantyExpiryDate,
};
formData.append("product", data);
formData.append("productPhoto", productData[0].productPhoto);
const config = {
headers: {
apiKey: api_key,
"Content-Type": "multipart/form-data",
},
};
console.log(config.headers);
return axios.post(`${API_BASE_URL}/products`, formData, config.headers);
}
I have specified the content type but still I am getting the below error:
{
"timestamp": "05-20-2023 01:27:36",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/octet-stream' not supported",
"path": "/product-crud/products"
}
The backend is okay. I have checked with Postman. Anyone can help me?