imazen / imageflow-dotnet-server

A super-fast image server to speed up your site - deploy as a microservice, serverless, or embeddable.
https://docs.imageflow.io
GNU Affero General Public License v3.0
246 stars 33 forks source link

Querystring API not working in Episerver 12 site? #58

Closed peter3 closed 2 years ago

peter3 commented 2 years ago

I am trying out Imageflow on an episerver 12 site (local development so far) but have some issues with the Imageflow querystring API not triggering

I have the following packages installed:

    <PackageReference Include="EPiServer.CMS" Version="12.7.0" />
    <PackageReference Include="Imageflow.AllPlatforms" Version="0.8.1" />
    <PackageReference Include="Imageflow.Server" Version="0.6.5" />

I have the following in Startup.Configure:

        app.UseImageflow(new ImageflowMiddlewareOptions()
            .SetMapWebRoot(true)
            .AddCommandDefault("format", "webp")
            .AddCommandDefault("webp.quality", "80")
            .SetMyOpenSourceProjectUrl("https://github.com/xxxxx/xxxx")
        //.SetDefaultCacheControlString("public, max-age=2592000")
        );

        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapContent();
            //endpoints.MapDefaultControllerRoute();
            // Imageflow test endpoint:
            endpoints.MapGet("/test-image", async context =>
            {
                context.Response.ContentType = "text/html";
                await context.Response.WriteAsync("<img src=\"test.jpg?width=450\" />");
            });
        });

Additionally, the .AddCommandDefault()s are not applied in any of the test cases.

What am I doing wrong?

lilith commented 2 years ago

At least one querystring command is needed for defaults to be applied. -> https://github.com/imazen/imageflow-dotnet-server/blob/ca7cb15717fc6cc5a2c1f59ba4f76598865666d0/src/Imageflow.Server/ImageJobInfo.cs#L222

You can apply such a default to all images by using the Imageflow rewriting method.

.AddRewriteHandler("/gallery", args => { //TODO: Set something if it isn't already set, on my phone here args.Query["watermark"] = "imazen"; })

Images uploaded to EPIServer aren't accessible to Imageflow unless you tell it how to get to them. There's an example adapter / blob service here: https://github.com/imazen/imageflow-dotnet-server/blob/main/examples/Imageflow.Server.Example/CustomBlobService.cs

I believe there are a few ImageResizer EPiServer adapters out there, but Imageflow needs one. Which version of EPIServer are you using?

On Sat, Jun 4, 2022, 4:12 AM Peter Törnqvist @.***> wrote:

I am trying out Imageflow on an episerver 12 site (local development so far) but have some issues with the Imageflow querystring API not triggering

I have the following packages installed:

<PackageReference Include="EPiServer.CMS" Version="12.7.0" />
<PackageReference Include="Imageflow.AllPlatforms" Version="0.8.1" />
<PackageReference Include="Imageflow.Server" Version="0.6.5" />

I have the following in Startup.Configure:

  app.UseImageflow(new ImageflowMiddlewareOptions()
      .SetMapWebRoot(true)
      .AddCommandDefault("format", "webp")
      .AddCommandDefault("webp.quality", "80")
      .SetMyOpenSourceProjectUrl("https://github.com/xxxxx/xxxx")
  //.SetDefaultCacheControlString("public, max-age=2592000")
  );

  app.UseStaticFiles();
  app.UseRouting();
  app.UseAuthentication();
  app.UseAuthorization();

  app.UseEndpoints(endpoints =>
  {
      endpoints.MapContent();
      //endpoints.MapDefaultControllerRoute();
      // Imageflow test endpoint:
      endpoints.MapGet("/test-image", async context =>
      {
          context.Response.ContentType = "text/html";
          await context.Response.WriteAsync("<img src=\"test.jpg?width=450\" />");
      });
  });

Additionally, the .AddCommandDefault()s are not applied in any of the test cases.

What am I doing wrong?

— Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet-server/issues/58, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH2NZOFYU35XV2K7ZZLVNMT2HANCNFSM5X3GWEPA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

peter3 commented 2 years ago

Thanks for the quick reply!

I have now implemented an IBlobProvider for Episerver images and it seems to work very well. For some reason this also made https://localhost:5000/test-image work, not sure why.

The only thing left is the .AddCommandDefault() calls that doesn't add the default params to the url. I don't quite understand your reply regarding this, isn't "width" enough for the defaults to be applied?

peter3 commented 2 years ago

Update: the .AddCommandDefault() calls looks to be working now when I check the output from the webserver. Not sure what has changed, but anyway all my issues are resolved. Thanks

lilith commented 2 years ago

That's good to hear, I don't have any ideas why it might not have been working, width would definitely trigger it. If you have the permission, would you be up for sharing the IBlobProvider implementation under Apache 2/MIT? I know there are other users who could benefit.

lilith commented 1 year ago

'Width' should definitely be enough for command defaults to be applied.

Could you share all your config code and versions?

On Tue, Jun 7, 2022, 3:44 AM Peter Törnqvist @.***> wrote:

Thanks for the quick reply!

I have now implemented an IBlobProvider for Episerver images and it seems to work very well. For some reason this also made https://localhost:5000/test-image work, not sure why.

The only thing left is the .AddCommandDefault() calls that doesn't add the default params to the url. I don't quite understand your reply regarding this, isn't "width" enough for the defaults to be applied?

— Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet-server/issues/58#issuecomment-1148442761, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LHYNNJRLMHDNN5OKPEDVN4KXZANCNFSM5X3GWEPA . You are receiving this because you commented.Message ID: @.***>