I am trying to upload an audio blob file from Angular, but I am not receiving any files on the server side. I tested my ASP.NET Web API code in ApiDog, and It's working without any issues. I need some suggestions about this issue.
My Angular code:
upload(blob: Blob): void {
const formData = new FormData();
formData.append("file",blob,'audio file');
let headers = new HttpHeaders({
'Content-Type': 'multipart/form-data'});
let options = { headers: headers };
this.http.post('/api/fileUpload', formData,options).subscribe(
(response) => console.log(response),
(error) => console.log(error)
);
}
ASP.NET Web API:
I check the file count in the following code block on my controller.
var httpRequest = HttpContext.Current.Request;
if (httpRequest.Files.Count > 0)
{
var file = httpRequest.Files[0];
}
Thanks for your time!
HttpContext: stackoverflow.com/a/20356591/1807452HttpContext.Request.Form.Files? What is the alternative of Httpcontext.Current.Request.Files in Asp.Net Core 2.0?