Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WriteHttpFileResponse Activity #4445

Merged
merged 8 commits into from
Sep 16, 2023
Merged

WriteHttpFileResponse Activity #4445

merged 8 commits into from
Sep 16, 2023

Conversation

sfmskywalker
Copy link
Member

@sfmskywalker sfmskywalker commented Sep 15, 2023

This PR adds a new activity that makes it simple for workflows to send files to the client (e.g. browser and other HTTP clients).

The activity supports various inputs, such as URLs, Streams and binary data (byte arrays).

BREAKING CHANGES

This PR introduces a breaking DB schema change by adding a new field called SerializedMetadata to the StoredBookmarks table.

Usage

The following is a simple example showing that you can provide one or more URLS to download and then send back to the client:

image

As mentioned, the contents of the array can contain mixed types: Urls (shown above), Streams, binary data and Downloadable object instances.

The Downloadable class looks like this (simplified for brevity):

public class Downloadabe
{
   public Stream Stream { get; set; }
   public string? Filename { get; set; }
   public string? ContentType { get; set; }
}

You can manually construct instances of this type in JavaScript to control the filename to use, for example.
An sample scenario could be where you have a custom activity that loads a file from a protected location and returns it as a stream. You can capture this stream using a workflow variable and then use it in the WriteFileHttpResponse activity using the following JS:

var stream = getStream(); // Assume the stream was captured in a workflow variable called Stream.
return new Downloadable
{
   Stream: stream,
   Filename: "my-file.dat"
}

=== auto-pr-body ===

Summary:
This pull request adds new parameters and refactors existing code related to bookmarks. New parameters for IDictionary<string, string> have been added to the CreateBookmark method, CreateBookmarkArgs model and StoredBookmark model. The BookmarkOptions parameter has been renamed to CreateBookmarkArgs and dispatched to methods in ActivityExecutionContext, Event, and BackgroundActivityInvokerMiddleware. Additionally the mods argument has been changed from "Management" to "Runtime" in the update-migrations.sh script.

List of changes:

  • Added a parameter for an IDictionary<string, string> to the CreateBookmark method.
  • Renamed BookmarkOptions to CreateBookmarkArgs.
  • Added an optional parameter for IDictionary<string, string> to the CreateBookmarkArgs, Bookmark, and StoredBookmark models
  • Changed CreateBookmark and DispatchWorkflow methods to use the new CreateBookmarkArgs parameter.
  • Changed Event and BackgroundActivityInvokerMiddleware methods to use the new CreateBookmarkArgs parameter.
  • Changed argument name from BookmarkOptions to CreateBookmarkArgs in BackgroundActivityInvokerMiddleware.cs
  • Changed mods from "Management" to "Runtime" in update-migrations.sh

Refactoring Target:

  • Extract common logic to a method for creating arguments for CreateBookmark.
  • Refactor the parameter list for CreateBookmarkArgs to group related parameters together.
  • Refactor parameter names on CreateBookmark to be more descriptive.
  • Abstract out common code related to setting and consuming the bookmark payload in BackgroundActivityInvokerMiddleware.cs into separate methods.
  • Further split out into separate files parts of the update-migrations.sh script that are related to different parts of the workflow.

@sfmskywalker sfmskywalker added the elsa 3 This issue is specific to Elsa 3 label Sep 15, 2023
@sfmskywalker sfmskywalker marked this pull request as ready for review September 16, 2023 08:48
@sfmskywalker sfmskywalker merged commit bb2fa55 into v3 Sep 16, 2023
2 checks passed
@sfmskywalker sfmskywalker deleted the v3-http-file-download-basic branch September 16, 2023 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
elsa 3 This issue is specific to Elsa 3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant