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

Commit feb80f0

Browse files
committed
Expose GetName extension on IFormFile
1 parent 9887fe0 commit feb80f0

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/Microsoft.AspNet.Http/FormFileCollection.cs

Lines changed: 2 additions & 11 deletions
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
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.Net.Http.Headers;
5+
6+
namespace Microsoft.AspNet.Http
7+
{
8+
public static class FormFileExtensions
9+
{
10+
public static string GetName(this IFormFile file)
11+
{
12+
// Content-Disposition: form-data; name="myfile1"; filename="Misc 002.jpg"
13+
ContentDispositionHeaderValue cd;
14+
if (ContentDispositionHeaderValue.TryParse(file.ContentDisposition, out cd))
15+
{
16+
return HeaderUtilities.RemoveQuotes(cd.Name);
17+
}
18+
19+
return string.Empty;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)