Copied to clipboard

Flag this post as spam?

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


  • Josefine 27 posts 139 karma points
    Dec 07, 2023 @ 16:44
    Josefine
    2

    How can I download stp file from my website?

    Hi

    I have a a-tag with download attribute and a file from media in href, which is an stp file and I can't download the file on my website.

    <a href="media/folder/file" download>
    

    I have the same code for websites in Umbraco version 7 and 8 - it works but now I'm using Umbraco version 12.

    Are there any security settings in Umbraco 12 for download files?

    Josefine

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Dec 07, 2023 @ 17:55
    Huw Reddick
    1

    Hi,

    You will probably need to add a new file content provider in the usestaticfiles initializer. I think I may have an example, will dig it out in the morning

  • Josefine 27 posts 139 karma points
    Dec 07, 2023 @ 18:19
    Josefine
    1

    Hi thanks for writing to me. An example would be great 😃

  • Brendan Rice 538 posts 1101 karma points
    Dec 08, 2023 @ 01:58
    Brendan Rice
    101

    This code might not be perfect but I tested it and it seems to work.

    The problem is that the mime type ".stp" isn't recognised by the server as being downloadable. We have to add in code to tell the server to download .stp files.

    Add this in startup.cs > Configure method just above app.UseUmbraco():

            var provider = new FileExtensionContentTypeProvider();
            // Set the MIME type for .stp files
            provider.Mappings[".stp"] = "application/octet-stream";
    
            // Apply middleware only for .stp file requests
            app.UseWhen(
                context => context.Request.Path.HasValue && context.Request.Path.Value.EndsWith(".stp", StringComparison.OrdinalIgnoreCase),
                appBuilder =>
                {
                    appBuilder.UseStaticFiles(new StaticFileOptions
                    {
                        ContentTypeProvider = provider
                    });
                }
            );
    

    Let me know if it works.

  • Josefine 27 posts 139 karma points
    Dec 19, 2023 @ 15:13
    Josefine
    1

    Thanks for your help. It works 😃

  • Brendan Rice 538 posts 1101 karma points
    Dec 19, 2023 @ 15:19
    Brendan Rice
    0

    Glad it worked :D

Please Sign in or register to post replies

Write your reply to:

Draft