I'm struggling with uploading an xml file with axios to my asp .net server. I'm using the following code from the vue side to get an xml file, which is working and afterwards upload it to my server:
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 got this function:
[HttpPost]
public IActionResult Post(object xml)
{
// Do something with the xml
...
}
Uploading the file results in a code 415 : Unsupported Media Type.
I found some suggestions to add the xml formatter to my project, which didn't work and furthermore I don't want to parse the xml file, I just want to save the file to my filesystem.
I tried to upload the rawFile and the parsed text in combination with different media types, e.g. text/plain, text/xml and application/xml
I also tried to add the accept-language
I also tried the proposed way from the microsoft documentation with this function header:
public async Task<IActionResult> OnPostUploadAsync(List<IFormFile> files)
And I tried to debug this with Postman, uploading a simple image, which gave me the same error.