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

Commit f8bb6f6

Browse files
committed
Added FileName to IFormFile
1 parent 907b020 commit f8bb6f6

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/Microsoft.AspNet.Http.Abstractions/IFormFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public interface IFormFile
2020

2121
string Name { get; }
2222

23+
string FileName { get; }
24+
2325
Stream OpenReadStream();
2426
}
2527
}

src/Microsoft.AspNet.Http/Features/FormFeature.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ private async Task<IFormCollection> InnerReadFormAsync(CancellationToken cancell
149149
// Find the end
150150
await section.Body.DrainAsync(cancellationToken);
151151

152-
var name = HeaderUtilities.RemoveQuotes(contentDisposition.Name);
153-
154-
var file = new FormFile(_request.Body, section.BaseStreamOffset.Value, section.Body.Length, name)
152+
var file = new FormFile(_request.Body, section.BaseStreamOffset.Value, section.Body.Length, contentDisposition)
155153
{
156154
Headers = new HeaderDictionary(section.Headers),
157155
};

src/Microsoft.AspNet.Http/Features/FormFile.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using System.IO;
55
using Microsoft.AspNet.Http.Internal;
6+
using Microsoft.Net.Http.Headers;
7+
using static Microsoft.Net.Http.Headers.HeaderUtilities;
68

79
namespace Microsoft.AspNet.Http.Features.Internal
810
{
@@ -11,12 +13,13 @@ public class FormFile : IFormFile
1113
private readonly Stream _baseStream;
1214
private readonly long _baseStreamOffset;
1315

14-
public FormFile(Stream baseStream, long baseStreamOffset, long length, string name)
16+
public FormFile(Stream baseStream, long baseStreamOffset, long length, ContentDispositionHeaderValue contentDisposition)
1517
{
1618
_baseStream = baseStream;
1719
_baseStreamOffset = baseStreamOffset;
1820
Length = length;
19-
Name = name;
21+
Name = RemoveQuotes(contentDisposition.Name) ?? string.Empty;
22+
FileName = RemoveQuotes(contentDisposition.FileName) ?? string.Empty;
2023
}
2124

2225
public string ContentDisposition
@@ -37,6 +40,8 @@ public string ContentType
3740

3841
public string Name { get; }
3942

43+
public string FileName { get; }
44+
4045
public Stream OpenReadStream()
4146
{
4247
return new ReferenceReadStream(_baseStream, _baseStreamOffset, Length);

test/Microsoft.AspNet.Http.Tests/FormFeatureTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public async Task ReadFormAsync_MultipartWithFile_ReturnsParsedFormCollection()
216216

217217
var file = formCollection.Files["myfile1"];
218218
Assert.Equal("myfile1", file.Name);
219+
Assert.Equal("temp.html", file.FileName);
219220
Assert.Equal("text/html", file.ContentType);
220221
Assert.Equal(@"form-data; name=""myfile1""; filename=""temp.html""", file.ContentDisposition);
221222
var body = file.OpenReadStream();

0 commit comments

Comments
 (0)