2023-09-16 09:06:56 +00:00
|
|
|
using Elsa.Http.Abstractions;
|
|
|
|
|
using Elsa.Http.Contexts;
|
|
|
|
|
using Elsa.Http.Models;
|
|
|
|
|
|
2023-09-17 20:35:13 +00:00
|
|
|
namespace Elsa.Http.DownloadableContentHandlers;
|
2023-09-16 09:06:56 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles content that represents a downloadable binary file.
|
|
|
|
|
/// </summary>
|
2023-09-17 20:35:13 +00:00
|
|
|
public class BinaryDownloadableContentHandler : DownloadableContentHandlerBase
|
2023-09-16 09:06:56 +00:00
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override bool GetSupportsContent(object content) => content is byte[];
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override Downloadable GetDownloadable(DownloadableContext context)
|
|
|
|
|
{
|
|
|
|
|
var bytes = (byte[]) context.Content;
|
|
|
|
|
var stream = new MemoryStream(bytes);
|
|
|
|
|
var fileName = "file.bin";
|
|
|
|
|
var contentType = "application/octet-stream";
|
2023-09-17 20:35:13 +00:00
|
|
|
return new(stream, fileName, contentType);
|
2023-09-16 09:06:56 +00:00
|
|
|
}
|
|
|
|
|
}
|