using System.Text.Json.Serialization;
namespace Elsa.Http.Models;
///
/// Represents a downloadable object.
///
public class HttpFile
{
///
/// Initializes a new instance of the class.
///
[JsonConstructor]
public HttpFile()
{
}
///
/// Initializes a new instance of the class.
///
/// The stream to download.
/// The filename to use when downloading the stream.
/// The content type to use when downloading the stream.
/// The ETag to use when downloading the stream.
public HttpFile(Stream stream, string? filename = default, string? contentType = default, string? eTag = default)
{
Stream = stream;
Filename = filename;
ContentType = contentType;
ETag = eTag;
}
///
/// The file stream.
///
public Stream Stream { get; set; } = default!;
///
/// The filename.
///
public string? Filename { get; set; }
///
/// The content type.
///
public string? ContentType { get; set; }
///
/// The ETag.
///
public string? ETag { get; set; }
///
/// Gets the file bytes.
///
public byte[] GetBytes()
{
using var memoryStream = new MemoryStream();
if (Stream.CanSeek) Stream.Seek(0, SeekOrigin.Begin);
Stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
}