-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathHttpFile.cs
More file actions
58 lines (48 loc) · 1.52 KB
/
Copy pathHttpFile.cs
File metadata and controls
58 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#nullable enable
using System;
using System.IO;
using ServiceStack.Web;
namespace ServiceStack.Host;
public class HttpFile : IHttpFile
{
public HttpFile() {}
public HttpFile(IHttpFile file)
{
Name = file.Name;
FileName = file.FileName;
ContentLength = file.ContentLength;
ContentType = file.ContentType;
InputStream = file.InputStream;
}
public string Name { get; set; }
public string FileName { get; set; }
public long ContentLength { get; set; }
public string ContentType { get; set; }
public virtual Stream InputStream { get; set; }
}
#if NET6_0_OR_GREATER
public class HttpFileContent : HttpFile
{
System.Net.Http.HttpContent content;
public HttpFileContent(System.Net.Http.HttpContent content)
{
this.content = content;
this.ContentType = content.Headers.ContentType?.MediaType ?? MimeTypes.Binary;
if (content.Headers.ContentLength != null)
this.ContentLength = content.Headers.ContentLength.Value;
var contentDisposition = content.Headers.ContentDisposition;
if (contentDisposition != null)
{
Name = contentDisposition.Name;
FileName = contentDisposition.FileName;
if (contentDisposition.Size != null)
ContentLength = contentDisposition.Size.Value;
}
}
public override Stream InputStream
{
get => base.InputStream ??= content.ReadAsStream();
set => base.InputStream = value;
}
}
#endif