private async Task <string> UploadAnyFileAsync( HttpContent httpContent, string[] allowedExtensions, string folderPath) { if (!httpContent.IsMimeMultipartContent("form-data")) { throw new NotSupportedException(); } var provider = new CustomMultipartStreamProvider(folderPath); await httpContent.ReadAsMultipartAsync(provider); var fullFileName = provider.FileData.First().LocalFileName; var extension = GetFileExtension(fullFileName); if (!allowedExtensions.Contains(extension)) { await Task.Factory.StartNew(() => File.Delete(fullFileName)); throw new InvalidDataException("Extension {0} is not allowed".FormatString(extension)); } return(fullFileName); }
private async Task<string> UploadAnyFileAsync( HttpContent httpContent, string[] allowedExtensions, string folderPath) { if (!httpContent.IsMimeMultipartContent("form-data")) { throw new NotSupportedException(); } var provider = new CustomMultipartStreamProvider(folderPath); await httpContent.ReadAsMultipartAsync(provider); var fullFileName = provider.FileData.First().LocalFileName; var extension = GetFileExtension(fullFileName); if (!allowedExtensions.Contains(extension)) { await Task.Factory.StartNew(() => File.Delete(fullFileName)); throw new InvalidDataException("Extension {0} is not allowed".FormatString(extension)); } return fullFileName; }