abenci
abenci

Reputation: 8651

How do I check on disk if the thumbnail image is present and optionally use it in ASP.NET MVC 3?

We are trying to generate image gallery thumbnail images programmatically in our ASP.NET MVC3 website instead of doing this manually all the times.

We are looking for implementing a function that checks in the TEMP folder is the thumbnail is present, otherwise creates and uses it.

Is a controller action the right place to implement this? What should this action return?

We already implemented the image generation on the fly with several problems when many thumbnail images are on the gallery page (some are always missing, because of too many hits?) and we'd like to try a different approach.

Thanks.

Upvotes: 0

Views: 100

Answers (3)

Nikola Sivkov
Nikola Sivkov

Reputation: 2852

I would advise you not to create image/thumbnail generator yourself , but rather use http://imageresizing.net a C# library that has many advanced functions and plugins ( cahcing , creating thumbnails , dynamic resizing, etc, etc.)

Here is the NuGet url : http://nuget.org/packages/ImageResizer/

Here is a sample config i use

<resizer>
  <plugins>
    <add name="MvcRoutingShim" />
    <add name="DiskCache" />
  </plugins>
  <diskCache dir="~/imagecache" autoClean="false" hashModifiedDate="true" enabled="true" subfolders="32" cacheAccessTimeout="3000" asyncWrites="false" asyncBufferSize="10485760" />
  <clientcache minutes="7200" />
</resizer>

Upvotes: 1

Ant P
Ant P

Reputation: 25221

Personally, I would create an ImageThumbnailService or similar and expose it to your web app through an appropriate interface. That way, your application need only ask the service for a thumbnail and the service can do the worrying about whether or not the file exists, etc., calling off to some other class to create the thumbnail if it doesn't.

Upvotes: 0

Jakub Konecki
Jakub Konecki

Reputation: 46008

I would do such processing in a separate process, preferably Windows Service.

AppDomain can be recycled by IIS and your thumbnail processing thread may be killed in the middle of work. The same applies when the new version of the website is deployed or configuration changed.

Monitoring and maintenance of the background thread in IIS worker process would be probably more difficult than a separate Windows Service.

Upvotes: 0

Related Questions