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

Commit 746f121

Browse files
committed
Expose Name property on IFormFile
1 parent 9887fe0 commit 746f121

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

Diff for: src/Microsoft.AspNet.Http.Abstractions/IFormFile.cs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public interface IFormFile
1818

1919
long Length { get; }
2020

21+
string Name { get; }
22+
2123
Stream OpenReadStream();
2224
}
2325
}

Diff for: src/Microsoft.AspNet.Http/Features/FormFeature.cs

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

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

Diff for: src/Microsoft.AspNet.Http/Features/FormFile.cs

+9-10
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace Microsoft.AspNet.Http.Features.Internal
88
{
99
public class FormFile : IFormFile
1010
{
11-
private Stream _baseStream;
12-
private long _baseStreamOffset;
13-
private long _length;
11+
private readonly Stream _baseStream;
12+
private readonly long _baseStreamOffset;
1413

15-
public FormFile(Stream baseStream, long baseStreamOffset, long length)
14+
public FormFile(Stream baseStream, long baseStreamOffset, long length, string name)
1615
{
1716
_baseStream = baseStream;
1817
_baseStreamOffset = baseStreamOffset;
19-
_length = length;
18+
Length = length;
19+
Name = name;
2020
}
2121

2222
public string ContentDisposition
@@ -33,14 +33,13 @@ public string ContentType
3333

3434
public IHeaderDictionary Headers { get; set; }
3535

36-
public long Length
37-
{
38-
get { return _length; }
39-
}
36+
public long Length { get; }
37+
38+
public string Name { get; }
4039

4140
public Stream OpenReadStream()
4241
{
43-
return new ReferenceReadStream(_baseStream, _baseStreamOffset, _length);
42+
return new ReferenceReadStream(_baseStream, _baseStreamOffset, Length);
4443
}
4544
}
4645
}

Diff for: 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.Name));
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.Name));
3223
}
3324
}
3425
}

0 commit comments

Comments
 (0)