Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 5445250

Browse files
committedDec 4, 2015
Expose GetName extension on IFormFile
1 parent 9887fe0 commit 5445250

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed
 

‎src/Microsoft.AspNet.Http/FormFileCollection.cs

+2-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
5-
using Microsoft.Net.Http.Headers;
65

76
namespace Microsoft.AspNet.Http.Internal
87
{
@@ -15,20 +14,12 @@ public IFormFile this[string name]
1514

1615
public IFormFile GetFile(string name)
1716
{
18-
return Find(file => string.Equals(name, GetName(file.ContentDisposition)));
17+
return Find(file => string.Equals(name, file.GetName()));
1918
}
2019

2120
public IReadOnlyList<IFormFile> GetFiles(string name)
2221
{
23-
return FindAll(file => string.Equals(name, GetName(file.ContentDisposition)));
24-
}
25-
26-
private static string GetName(string contentDisposition)
27-
{
28-
// Content-Disposition: form-data; name="myfile1"; filename="Misc 002.jpg"
29-
ContentDispositionHeaderValue cd;
30-
ContentDispositionHeaderValue.TryParse(contentDisposition, out cd);
31-
return HeaderUtilities.RemoveQuotes(cd?.Name);
22+
return FindAll(file => string.Equals(name, file.GetName()));
3223
}
3324
}
3425
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.Net.Http.Headers;
2+
3+
namespace Microsoft.AspNet.Http
4+
{
5+
public static class FormFileExtensions
6+
{
7+
public static string GetName(this IFormFile file)
8+
{
9+
// Content-Disposition: form-data; name="myfile1"; filename="Misc 002.jpg"
10+
ContentDispositionHeaderValue cd;
11+
if (ContentDispositionHeaderValue.TryParse(file.ContentDisposition, out cd))
12+
{
13+
return HeaderUtilities.RemoveQuotes(cd.Name);
14+
}
15+
16+
return string.Empty;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)