I'm encountering difficulties when trying to upload an xml file using axios to my asp .net server. Below is the code snippet I am using on the vue side to retrieve and upload the xml file:
uploadXmlFile(file: any) {
const rawFile = new XMLHttpRequest();
rawFile.open('GET', file, false);
rawFile.onreadystatechange = () => {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status === 0) {
const allText = rawFile.responseText;
axios.post(`${url}`, rawFile, {
headers: {
'Content-Type': 'application/xml',
'Accept-Language': 'application/xml',
},
});
}
}
};
rawFile.send(null);
}
On the asp .net side, I have the following function:
[HttpPost]
public IActionResult Post(object xml)
{
// Do something with the xml
...
}
Unfortunately, attempting to upload the file results in a status code 415 : Unsupported Media Type.
I have tried implementing the xml formatter in my project based on suggestions found online, but it did not resolve the issue. Additionally, I want to emphasize that I do not intend to parse the xml file, only save it to my filesystem.
Various attempts were made by uploading the rawFile and parsed text with different media types such as text/plain, text/xml, and application/xml.
I also experimented with adding the accept-language header and attempted Microsoft's proposed method with the following function header:
public async Task<IActionResult> OnPostUploadAsync(List<IFormFile> files)
Further investigation was conducted using Postman to upload a basic image, which returned the same error message.