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

Commit ecad19d

Browse files
committed
Added FileName to IFormFile
1 parent d8704d2 commit ecad19d

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

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

+2
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

+1-3
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

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.IO;
55
using Microsoft.AspNet.Http.Internal;
6+
using Microsoft.Net.Http.Headers;
67

78
namespace Microsoft.AspNet.Http.Features.Internal
89
{
@@ -11,12 +12,13 @@ public class FormFile : IFormFile
1112
private readonly Stream _baseStream;
1213
private readonly long _baseStreamOffset;
1314

14-
public FormFile(Stream baseStream, long baseStreamOffset, long length, string name)
15+
public FormFile(Stream baseStream, long baseStreamOffset, long length, ContentDispositionHeaderValue contentDisposition)
1516
{
1617
_baseStream = baseStream;
1718
_baseStreamOffset = baseStreamOffset;
1819
Length = length;
19-
Name = name;
20+
Name = HeaderUtilities.RemoveQuotes(contentDisposition.Name) ?? string.Empty;
21+
FileName = HeaderUtilities.RemoveQuotes(contentDisposition.FileName) ?? string.Empty;
2022
}
2123

2224
public string ContentDisposition
@@ -37,6 +39,8 @@ public string ContentType
3739

3840
public string Name { get; }
3941

42+
public string FileName { get; }
43+
4044
public Stream OpenReadStream()
4145
{
4246
return new ReferenceReadStream(_baseStream, _baseStreamOffset, Length);

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

+1
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)