public async Task <HttpResponseMessage> CreateAudioFile(int songId) { var filesReadToProvider = await Request.Content.ReadAsMultipartAsync(); //var audioFilename = @"C:\Users\allan\Documents\musicLibrary\" + Guid.NewGuid().ToString("N") +".wav"; var stream = filesReadToProvider.Contents.First(); var fileBytes = await stream.ReadAsByteArrayAsync(); var ext = ""; var contentType = stream.Headers.ContentType.MediaType; if (contentType == "audio/mp3") { ext = ".mp3"; } else if (contentType == "audio/wav") { ext = ".wav"; } else if (contentType == "audio/x-m4a") { ext = ".m4a"; } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "unsupported file type")); } var audioFileName = @"C:\Users\allan\Documents\musicLibrary\" + Guid.NewGuid().ToString("N") + ext; File.WriteAllBytes(audioFileName, fileBytes); IOrganizerService organizerService = new OrganizerService(); int id = organizerService.CreateAudioFile(songId, audioFileName); return(Request.CreateResponse(HttpStatusCode.Created, id)); }