Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Warren Harding 132 posts 275 karma points
    Nov 29, 2023 @ 05:29
    Warren Harding
    0

    workflow for file download

    Hi folks, I'm trying to get a workflow to download a file and not having much luck - has anyone had success with this and could help?

    Currently, I have a file attribute that allows the client to select a media item, I can open this and using SendFileAsync can see it start to download... but then when "return WorkflowExecutionStatus.Completed" gets called the request gets interupted and the file gets cancelled.

    Here's what I believe is the offending portion of code:

    var filepath = new FileInfo(filename);
    
    var response = _httpContextAccessor.HttpContext?.Response;
    
    response.Clear();
    response.Headers.Add("Content-Disposition", "attachment;filename=" + filepath.Name);
    response.Headers.Add("Content-Length", filepath.Length.ToString());
    response.Headers.Add("Content-Transfer-Encoding", "binary");
    new FileExtensionContentTypeProvider().Mappings.TryGetValue(filepath.Extension, out var contenttype);
    response.ContentType = contenttype ?? "application/octet-stream";
    response.SendFileAsync(filepath.FullName);
    response.CompleteAsync();
    
    return WorkflowExecutionStatus.Completed;
    

    Any help would be greatly appreciated, thank you.

  • Warren Harding 132 posts 275 karma points
    Nov 29, 2023 @ 05:29
    Warren Harding
    0

    Sorry this should be in Ubmraco Forms category - I can't seem to move it.

  • Warren Harding 132 posts 275 karma points
    Dec 06, 2023 @ 22:01
    Warren Harding
    0

    Bump

  • Gilles 27 posts 109 karma points
    Apr 24, 2024 @ 15:27
    Gilles
    0

    Hi, I'm trying to do a similar thing. Using your code I do get the very same result as you. Download is being interrupted.

    Did you happen you find a solution?

    Regards

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies