Browse Source

v 4.1.1.0

Former-commit-id: 2f6b172392cb9955180ac153d260eb4cb4441442
Former-commit-id: 70f6be3cd0a97a828907f2d26f5e49d989e2b773
pull/17/head
James South 12 years ago
parent
commit
269cf6a2ae
  1. 48
      build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec
  2. 50
      build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec
  3. 56
      build/NuSpecs/ImageProcessor.Web.Config.nuspec
  4. 50
      build/NuSpecs/ImageProcessor.Web.nuspec
  5. 40
      build/NuSpecs/ImageProcessor.nuspec
  6. 2
      build/build.xml
  7. 7
      src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs
  8. 34
      src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs
  9. 4
      src/ImageProcessor.Web/Properties/AssemblyInfo.cs
  10. 130
      src/TestWebsites/MVC/TestImageService.cs
  11. 1
      src/TestWebsites/MVC/Test_Website_MVC.csproj

48
build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec

@ -1,31 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata> <metadata>
<id>ImageProcessor.Plugins.Cair</id> <id>ImageProcessor.Plugins.Cair</id>
<version>1.0.0.0</version> <version>1.0.0.0</version>
<title>ImageProcessor.Plugins.Cair</title> <title>ImageProcessor.Plugins.Cair</title>
<authors>James South</authors> <authors>James South</authors>
<owners>James South</owners> <owners>James South</owners>
<projectUrl>http://imageprocessor.org</projectUrl> <projectUrl>http://imageprocessor.org</projectUrl>
<iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl> <iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance> <requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Adds support to ImageProcessor for Content Aware Image Resizing. <description>Adds support to ImageProcessor for Content Aware Image Resizing.
If you use ImageProcessor please get in touch via my twitter @james_m_south If you use ImageProcessor please get in touch via my twitter @james_m_south
Feedback is always welcome</description> Feedback is always welcome</description>
<summary>Adds support to ImageProcessor for Content Aware Image Resizing.</summary> <summary>Adds support to ImageProcessor for Content Aware Image Resizing.</summary>
<releaseNotes /> <releaseNotes />
<copyright>James South</copyright> <copyright>James South</copyright>
<language>en-GB</language> <language>en-GB</language>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Cair Seam Carving</tags> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Cair Seam Carving</tags>
<dependencies> <dependencies>
<group targetFramework=".NETFramework4.5"> <group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.0.0.0" /> <dependency id="ImageProcessor" version="2.0.0.0" />
</group> </group>
</dependencies> </dependencies>
</metadata> </metadata>
<files> <files>
<file src="..\_BuildOutput\ImageProcessor.Plugins.Cair\lib\net45\ImageProcessor.Plugins.Cair.dll" target="lib\net45\ImageProcessor.Plugins.Cair.dll" /> <file src="..\_BuildOutput\ImageProcessor.Plugins.Cair\lib\net45\ImageProcessor.Plugins.Cair.dll" target="lib\net45\ImageProcessor.Plugins.Cair.dll" />
</files> </files>
</package> </package>

50
build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec

@ -1,32 +1,32 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata> <metadata>
<id>ImageProcessor.Plugins.WebP</id> <id>ImageProcessor.Plugins.WebP</id>
<version>1.0.1.0</version> <version>1.0.1.0</version>
<title>ImageProcessor.Plugins.WebP</title> <title>ImageProcessor.Plugins.WebP</title>
<authors>James South</authors> <authors>James South</authors>
<owners>James South</owners> <owners>James South</owners>
<projectUrl>http://imageprocessor.org</projectUrl> <projectUrl>http://imageprocessor.org</projectUrl>
<iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl> <iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance> <requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Adds support to ImageProcessor for the WebP image format. <description>Adds support to ImageProcessor for the WebP image format.
If you use ImageProcessor please get in touch via my twitter @james_m_south If you use ImageProcessor please get in touch via my twitter @james_m_south
Feedback is always welcome</description> Feedback is always welcome</description>
<summary>Adds support to ImageProcessor and ImageProcessor.Web for the WebP image format.</summary> <summary>Adds support to ImageProcessor and ImageProcessor.Web for the WebP image format.</summary>
<releaseNotes /> <releaseNotes />
<copyright>James South</copyright> <copyright>James South</copyright>
<language>en-GB</language> <language>en-GB</language>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff WebP</tags> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff WebP</tags>
<dependencies> <dependencies>
<group targetFramework=".NETFramework4.5"> <group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.0.0.0" /> <dependency id="ImageProcessor" version="2.0.0.0" />
</group> </group>
</dependencies> </dependencies>
</metadata> </metadata>
<files> <files>
<file src="..\content\ImageProcessor.Plugins.WebP\web.config.transform" target="content\web.config.transform" /> <file src="..\content\ImageProcessor.Plugins.WebP\web.config.transform" target="content\web.config.transform" />
<file src="..\_BuildOutput\ImageProcessor.Plugins.WebP\lib\net45\ImageProcessor.Plugins.WebP.dll" target="lib\net45\ImageProcessor.Plugins.WebP.dll" /> <file src="..\_BuildOutput\ImageProcessor.Plugins.WebP\lib\net45\ImageProcessor.Plugins.WebP.dll" target="lib\net45\ImageProcessor.Plugins.WebP.dll" />
</files> </files>
</package> </package>

56
build/NuSpecs/ImageProcessor.Web.Config.nuspec

@ -1,35 +1,35 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata> <metadata>
<id>ImageProcessor.Web.Config</id> <id>ImageProcessor.Web.Config</id>
<version>2.1.0.0</version> <version>2.1.0.0</version>
<title>ImageProcessor.Web.Config</title> <title>ImageProcessor.Web.Config</title>
<authors>James South</authors> <authors>James South</authors>
<owners>James South</owners> <owners>James South</owners>
<projectUrl>http://imageprocessor.org</projectUrl> <projectUrl>http://imageprocessor.org</projectUrl>
<iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl> <iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance> <requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Adds configuration to your ImageProcessor.Web solution to allow you to override the default settings. <description>Adds configuration to your ImageProcessor.Web solution to allow you to override the default settings.
If you use ImageProcessor please get in touch via my twitter @james_m_south If you use ImageProcessor please get in touch via my twitter @james_m_south
Feedback is always welcome</description> Feedback is always welcome</description>
<summary>ImageProcessor.Web configuration settings for ASP.NET websites.</summary> <summary>ImageProcessor.Web configuration settings for ASP.NET websites.</summary>
<releaseNotes /> <releaseNotes />
<copyright>James South</copyright> <copyright>James South</copyright>
<language>en-GB</language> <language>en-GB</language>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags>
<dependencies> <dependencies>
<group targetFramework=".NETFramework4.5"> <group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.1.0.0" /> <dependency id="ImageProcessor" version="2.1.0.0" />
<dependency id="ImageProcessor.Web" version="4.1.0.0" /> <dependency id="ImageProcessor.Web" version="4.1.0.0" />
</group> </group>
</dependencies> </dependencies>
</metadata> </metadata>
<files> <files>
<file src="..\..\src\ImageProcessor.Web\Configuration\Resources\cache.config" target="content\config\imageprocessor\cache.config" /> <file src="..\..\src\ImageProcessor.Web\Configuration\Resources\cache.config" target="content\config\imageprocessor\cache.config" />
<file src="..\..\src\ImageProcessor.Web\Configuration\Resources\processing.config" target="content\config\imageprocessor\processing.config" /> <file src="..\..\src\ImageProcessor.Web\Configuration\Resources\processing.config" target="content\config\imageprocessor\processing.config" />
<file src="..\..\src\ImageProcessor.Web\Configuration\Resources\security.config" target="content\config\imageprocessor\security.config" /> <file src="..\..\src\ImageProcessor.Web\Configuration\Resources\security.config" target="content\config\imageprocessor\security.config" />
<file src="..\content\ImageProcessor.Web.Config\web.config.transform" target="content\web.config.transform" /> <file src="..\content\ImageProcessor.Web.Config\web.config.transform" target="content\web.config.transform" />
</files> </files>
</package> </package>

50
build/NuSpecs/ImageProcessor.Web.nuspec

@ -1,34 +1,34 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata> <metadata>
<id>ImageProcessor.Web</id> <id>ImageProcessor.Web</id>
<version>4.1.0.0</version> <version>4.1.1.0</version>
<title>ImageProcessor.Web</title> <title>ImageProcessor.Web</title>
<authors>James South</authors> <authors>James South</authors>
<owners>James South</owners> <owners>James South</owners>
<projectUrl>http://imageprocessor.org</projectUrl> <projectUrl>http://imageprocessor.org</projectUrl>
<iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl> <iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance> <requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ImageProcessor.Web adds a configurable HttpModule to your website which allows on-the-fly processing of image files. The module also comes with a file and browser based cache that can handle millions of images, increasing your processing output and saving precious server memory. <description>ImageProcessor.Web adds a configurable HttpModule to your website which allows on-the-fly processing of image files. The module also comes with a file and browser based cache that can handle millions of images, increasing your processing output and saving precious server memory.
Methods include: Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency. Methods include: Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency.
If you use ImageProcessor please get in touch via my twitter @james_m_south If you use ImageProcessor please get in touch via my twitter @james_m_south
Feedback is always welcome</description> Feedback is always welcome</description>
<summary>An extension to ImageProcessor that allows on-the-fly processing of image files in an ASP.NET website</summary> <summary>An extension to ImageProcessor that allows on-the-fly processing of image files in an ASP.NET website</summary>
<releaseNotes /> <releaseNotes />
<copyright>James South</copyright> <copyright>James South</copyright>
<language>en-GB</language> <language>en-GB</language>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags>
<dependencies> <dependencies>
<group targetFramework=".NETFramework4.5"> <group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.1.0.0" /> <dependency id="ImageProcessor" version="2.1.0.0" />
</group> </group>
</dependencies> </dependencies>
</metadata> </metadata>
<files> <files>
<file src="..\content\ImageProcessor.Web\web.config.transform" target="content\web.config.transform" /> <file src="..\content\ImageProcessor.Web\web.config.transform" target="content\web.config.transform" />
<file src="..\_BuildOutput\ImageProcessor.Web\lib\net45\ImageProcessor.Web.dll" target="lib\net45\ImageProcessor.Web.dll" /> <file src="..\_BuildOutput\ImageProcessor.Web\lib\net45\ImageProcessor.Web.dll" target="lib\net45\ImageProcessor.Web.dll" />
</files> </files>
</package> </package>

40
build/NuSpecs/ImageProcessor.nuspec

@ -1,29 +1,29 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata> <metadata>
<id>ImageProcessor</id> <id>ImageProcessor</id>
<version>2.1.0.0</version> <version>2.1.0.0</version>
<title>ImageProcessor</title> <title>ImageProcessor</title>
<authors>James South</authors> <authors>James South</authors>
<owners>James South</owners> <owners>James South</owners>
<projectUrl>http://imageprocessor.org</projectUrl> <projectUrl>http://imageprocessor.org</projectUrl>
<iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl> <iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance> <requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Image Processor is an easy to use and extend processing library written in C#. Its fluent API makes common imaging tasks very simple to perform. <description>Image Processor is an easy to use and extend processing library written in C#. Its fluent API makes common imaging tasks very simple to perform.
Methods include; Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency. Methods include; Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency.
If you use ImageProcessor please get in touch on my twitter @james_m_south. If you use ImageProcessor please get in touch on my twitter @james_m_south.
Feedback is always welcome.</description> Feedback is always welcome.</description>
<summary>A library for manipulating image files written in C#.</summary> <summary>A library for manipulating image files written in C#.</summary>
<releaseNotes /> <releaseNotes />
<copyright>James South</copyright> <copyright>James South</copyright>
<language>en-GB</language> <language>en-GB</language>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Fluent Animated EXIF</tags> <tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Fluent Animated EXIF</tags>
</metadata> </metadata>
<files> <files>
<file src="..\_BuildOutput\ImageProcessor\lib\net40\ImageProcessor.dll" target="lib\net40\ImageProcessor.dll" /> <file src="..\_BuildOutput\ImageProcessor\lib\net40\ImageProcessor.dll" target="lib\net40\ImageProcessor.dll" />
<file src="..\_BuildOutput\ImageProcessor\lib\net45\ImageProcessor.dll" target="lib\net45\ImageProcessor.dll" /> <file src="..\_BuildOutput\ImageProcessor\lib\net45\ImageProcessor.dll" target="lib\net45\ImageProcessor.dll" />
</files> </files>
</package> </package>

2
build/build.xml

@ -13,7 +13,7 @@
<project> <project>
<name>ImageProcessor Web</name> <name>ImageProcessor Web</name>
<version>4.1.0.0</version> <version>4.1.1.0</version>
<folder>..\src\ImageProcessor.Web</folder> <folder>..\src\ImageProcessor.Web</folder>
<projfile>ImageProcessor.Web.csproj</projfile> <projfile>ImageProcessor.Web.csproj</projfile>
<outputs> <outputs>

7
src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs

@ -348,12 +348,9 @@ namespace ImageProcessor.Web.Configuration
IImageService imageService = Activator.CreateInstance(type) as IImageService; IImageService imageService = Activator.CreateInstance(type) as IImageService;
if (!string.IsNullOrWhiteSpace(config.Prefix)) if (!string.IsNullOrWhiteSpace(config.Prefix))
{ {
if (!string.IsNullOrWhiteSpace(config.Prefix)) if (imageService != null)
{ {
if (imageService != null) imageService.Prefix = config.Prefix;
{
imageService.Prefix = config.Prefix;
}
} }
} }

34
src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs

@ -280,11 +280,12 @@ namespace ImageProcessor.Web.HttpModules
if (currentService != null) if (currentService != null)
{ {
bool isFileLocal = currentService.IsFileLocalService; bool isFileLocal = currentService.IsFileLocalService;
bool hasMultiParams = request.Url.ToString().Count(f => f == '?') > 1;
string requestPath = string.Empty; string requestPath = string.Empty;
string queryString = string.Empty; string queryString = string.Empty;
string urlParameters = string.Empty; string urlParameters = string.Empty;
if (!isFileLocal) if (hasMultiParams)
{ {
// We need to split the querystring to get the actual values we want. // We need to split the querystring to get the actual values we want.
string urlDecode = HttpUtility.UrlDecode(request.QueryString.ToString()); string urlDecode = HttpUtility.UrlDecode(request.QueryString.ToString());
@ -376,9 +377,11 @@ namespace ImageProcessor.Web.HttpModules
{ {
byte[] imageBuffer; byte[] imageBuffer;
if (!isFileLocal) if (hasMultiParams)
{ {
Uri uri = new Uri(requestPath + "?" + urlParameters); Uri uri = string.IsNullOrWhiteSpace(urlParameters)
? new Uri(requestPath, UriKind.RelativeOrAbsolute)
: new Uri(requestPath + "?" + urlParameters, UriKind.RelativeOrAbsolute);
imageBuffer = await currentService.GetImage(uri); imageBuffer = await currentService.GetImage(uri);
} }
else else
@ -434,12 +437,21 @@ namespace ImageProcessor.Web.HttpModules
if (isFileLocal) if (isFileLocal)
{ {
// Set the headers and quit. // Set the headers and quit.
this.SetHeaders(context, (string)context.Items[CachedResponseTypeKey], new List<string> { requestPath, cachedPath }); // Some services might only provide filename so we can't monitor for the browser.
return; this.SetHeaders(
context,
(string)context.Items[CachedResponseTypeKey],
Path.GetFileName(requestPath) == requestPath ? new List<string> { cachedPath } : new List<string> { requestPath, cachedPath });
}
else
{
this.SetHeaders(context, (string)context.Items[CachedResponseTypeKey], new List<string> { cachedPath });
} }
this.SetHeaders(context, (string)context.Items[CachedResponseTypeKey], new List<string> { cachedPath }); // Complete the requests but don't abort the thread.
context.ApplicationInstance.CompleteRequest();
return;
} }
// The cached file is valid so just rewrite the path. // The cached file is valid so just rewrite the path.
@ -450,11 +462,6 @@ namespace ImageProcessor.Web.HttpModules
throw new HttpException(403, "Access denied"); throw new HttpException(403, "Access denied");
} }
} }
else if (!isFileLocal)
{
// Just re-point to the external url.
HttpContext.Current.Response.Redirect(requestPath);
}
} }
} }
@ -496,6 +503,9 @@ namespace ImageProcessor.Web.HttpModules
cache.SetExpires(DateTime.Now.ToUniversalTime().AddDays(maxDays)); cache.SetExpires(DateTime.Now.ToUniversalTime().AddDays(maxDays));
cache.SetMaxAge(new TimeSpan(maxDays, 0, 0, 0)); cache.SetMaxAge(new TimeSpan(maxDays, 0, 0, 0));
cache.SetRevalidation(HttpCacheRevalidation.AllCaches); cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
context.Items[CachedResponseTypeKey] = null;
context.Items[CachedResponseFileDependency] = null;
} }
/// <summary> /// <summary>

4
src/ImageProcessor.Web/Properties/AssemblyInfo.cs

@ -40,5 +40,5 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("4.1.0.0")] [assembly: AssemblyVersion("4.1.1.0")]
[assembly: AssemblyFileVersion("4.1.0.0")] [assembly: AssemblyFileVersion("4.1.1.0")]

130
src/TestWebsites/MVC/TestImageService.cs

@ -0,0 +1,130 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TestImageService.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// The test image service.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Test_Website_NET45
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Web;
using System.Web.Hosting;
using ImageProcessor.Web.Services;
/// <summary>
/// The test image service.
/// </summary>
public class TestImageService : IImageService
{
/// <summary>
/// The prefix for the given implementation.
/// </summary>
private string prefix = "testprovider.axd";
/// <summary>
/// Gets or sets the prefix for the given implementation.
/// <remarks>
/// This value is used as a prefix for any image requests that should use this service.
/// </remarks>
/// </summary>
public string Prefix
{
get
{
return this.prefix;
}
set
{
this.prefix = value;
}
}
/// <summary>
/// Gets a value indicating whether the image service requests files from
/// the locally based file system.
/// </summary>
public bool IsFileLocalService
{
get
{
return true;
}
}
/// <summary>
/// Gets or sets any additional settings required by the service.
/// </summary>
public Dictionary<string, string> Settings { get; set; }
/// <summary>
/// Gets or sets the white list of <see cref="System.Uri"/>.
/// </summary>
public Uri[] WhiteList { get; set; }
/// <summary>
/// Gets a value indicating whether the current request passes sanitizing rules.
/// </summary>
/// <param name="path">
/// The image path.
/// </param>
/// <returns>
/// <c>True</c> if the request is valid; otherwise, <c>False</c>.
/// </returns>
public bool IsValidRequest(string path)
{
return true;
}
/// <summary>
/// Gets the image using the given identifier.
/// </summary>
/// <param name="id">
/// The value identifying the image to fetch.
/// </param>
/// <returns>
/// The <see cref="System.Byte"/> array containing the image data.
/// </returns>
public async Task<byte[]> GetImage(object id)
{
const string AppData = "~/App_Data/images";
string imageRoot = HostingEnvironment.MapPath(AppData);
if (imageRoot == null)
{
throw new HttpException(404, "No root path found to serve " + id);
}
// In this instance we are just processing a set path.
// If you are using the querystring params as a means of identifying the correct image
// then you can do something with it here.
string path = Path.Combine(imageRoot, id.ToString().Split(new[] { '&', '?' })[0]);
byte[] buffer;
// Check to see if the file exists.
// ReSharper disable once AssignNullToNotNullAttribute
FileInfo fileInfo = new FileInfo(path);
if (!fileInfo.Exists)
{
throw new HttpException(404, "Nothing found at " + id);
}
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true))
{
buffer = new byte[file.Length];
await file.ReadAsync(buffer, 0, (int)file.Length);
}
return buffer;
}
}
}

1
src/TestWebsites/MVC/Test_Website_MVC.csproj

@ -109,6 +109,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="TestImageService.cs" />
<Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs"> <Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon> <DependentUpon>Global.asax</DependentUpon>

Loading…
Cancel
Save