-
Notifications
You must be signed in to change notification settings - Fork 18
/
FileParameter.cs
82 lines (72 loc) · 2.58 KB
/
FileParameter.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Infobip Client API Libraries OpenAPI Specification
* OpenAPI specification containing public endpoints supported in client API libraries.
*
* Contact: support@infobip.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit the class manually.
*/
using System.IO;
namespace Infobip.Api.Client.Client
{
/// <summary>
/// Represents a File passed to the API as a Parameter, allows using different backends for files
/// </summary>
public class FileParameter
{
/// <summary>
/// Construct a FileParameter just from the contents, will extract the filename from a filestream
/// </summary>
/// <param name="content"> The file content </param>
public FileParameter(Stream content)
{
if (content is FileStream fs)
Name = Path.GetFileName(fs.Name);
Content = content;
}
/// <summary>
/// Construct a FileParameter from name and content
/// </summary>
/// <param name="filename">The filename</param>
/// <param name="content">The file content</param>
public FileParameter(string filename, Stream content)
{
Content = content;
Name = filename;
}
/// <summary>
/// Construct a FileParameter from name and content
/// </summary>
/// <param name="filename">The filename</param>
/// <param name="contentType">The content type of the file</param>
/// <param name="content">The file content</param>
public FileParameter(string filename, string contentType, Stream content)
{
Content = content;
ContentType = contentType;
Name = filename;
}
/// <summary>
/// The content of the file
/// </summary>
public Stream Content { get; set; }
/// <summary>
/// The content type of the file
/// </summary>
public string ContentType { get; set; } = "application/octet-stream";
/// <summary>
/// The filename
/// </summary>
public string Name { get; set; } = "no_name_provided";
/// <summary>
/// Implicit conversion of stream to file parameter. Useful for backwards compatibility.
/// </summary>
/// <param name="s">Stream to convert</param>
/// <returns>FileParameter</returns>
public static implicit operator FileParameter(Stream s)
{
return new FileParameter(s);
}
}
}