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
252 stars 33 forks source link

Serving extensionless files from Azure blob container #27

Closed sblomstrand closed 3 years ago

sblomstrand commented 3 years ago

Is there any way I can serve extension-less files (I use GUIDs like 381b2d2e-009f-4e53-95cb-d9c3b143722c as filenames) from an Azure blob container?

JayVDZ commented 3 years ago

Oh I'm glad you asked, I'm interested in this as well.

lilith commented 3 years ago

Right now we rely on extensions to determine what mime type to serve in cases where the output format is not set in the querystring.

So not yet. We would have to open the file contents to inspect the file headers to get around that, which would add a big performance penalty.

Would these files only be images?

On Fri, Oct 23, 2020, 8:59 AM Jay Van der Zant notifications@github.com wrote:

Oh I'm glad you asked, I'm interested in this as well.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet-server/issues/27#issuecomment-715395179, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH6ZB6TZY6Q7EGIMHGTSMGK5BANCNFSM4S4S434A .

sblomstrand commented 3 years ago

Yes, only images. I have the content type set correctly on the blob so I guess opening the file is not really necessary.

lilith commented 3 years ago

The problem is when the file is cached - since there's no metadata store in DiskCache, we rely on the URL to tell us the content type. Relying on the source blob would require re-fetching the data for each request which would defeat caching.

sblomstrand commented 3 years ago

Yes, I've been looking through the code and can see that. Regarding the content type - wouldn't it be better to add that as a prop to IBlobData? If it's a physical file then you can use the extension, if it's an Azure/S3/Remote you can always get the content type from the response.

lilith commented 3 years ago

I'm pretty sure in all cases I'll have to inspect the file stream and read the magic bytes, so it probably doesn't make sense to rely on hearsay content type anyway. If DiskCache could store content type, things would be different, but I don't want to double the number of files in the cache for that. After review I think inspecting bytes during streaming can be performant enough.

ImageflowMiddleware doesn't currently even look at requests without an image extension. How would you expect that API to look like? I wouldn't want to clobber non-image endpoints.

lilith commented 3 years ago

I've implemented content-type detection from magic bytes.

Still determining how to design the API for extensionless endpoints. Any ideas?

lilith commented 3 years ago

Implemented in https://github.com/imazen/imageflow-dotnet-server/releases/tag/v0.3.12

sblomstrand commented 3 years ago

Sorry for the lack of responses on my side, I've been away. Great work! Thank you! 👍

lilith commented 3 years ago

Thanks, please let me know if/when you deploy it!

On Fri, Oct 30, 2020, 7:16 AM Sten Blomstrand notifications@github.com wrote:

Sorry for the lack of responses on my side, I've been away. Great work! Thank you! 👍

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet-server/issues/27#issuecomment-719546006, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH5HSJALUKTNZHE7NZ3SNK4ERANCNFSM4S4S434A .

sblomstrand commented 3 years ago

I've deployed this now, works like a charm! 👍