Reputation: 12438
I am using the S3Reader plugin with ImageResizer to read deliver resized images from Amazon.
I am having troubles getting it working in my production environment mainly because I am unable to see what is going on under the covers.
I have added substantial logging and I know that the ImageMissing event is being fired, when I request the expected image.
If I check the url manually the image there, so the only thing I can think is that somewhere in the processing of ImageResizer via the S3Reader plugin?
So how can I see what the Url that ImageResizer is using to request the image from Amazon?
I suspect that because my bucket is in the AisaPac region it is somehow not using the correct url?
Some things to note, I only process images on the media
subdomain and I re-write the url (this could impact it too?)
My code and config to follow:
<resizer>
<diskcache dir="~/app_data" autoClean="true" />
<clientcache minutes="1440" />
<plugins>
<add name="MvcRoutingShim" />
<add name="S3Reader" buckets="media.domain.com" useSubdomains="true" />
<add name="DiskCache" />
</plugins>
</resizer>
private static void ImageResizer_ReWrite(IHttpModule sender, HttpContext context, IUrlEventArgs args)
{
string subDomain = context.Request.Url.SubDomain();
if (string.IsNullOrWhiteSpace(subDomain) || subDomain != AppSettings.MediaSubDomain)
return;
args.VirtualPath = string.Format("/s3/{0}", AppSettings.AmazonS3BucketName) + args.VirtualPath;
Logger.Error("New VirtualPath: " + args.VirtualPath);
}
private static void ImageResizer_OnPostAuthorizeRequestStart(IHttpModule sender2, HttpContext context)
{
var subDomain = context.Request.Url.SubDomain();
if (string.IsNullOrWhiteSpace(subDomain) || subDomain != AppSettings.MediaSubDomain)
return;
Config.Current.Pipeline.SkipFileTypeCheck = true;
Config.Current.Pipeline.ModifiedQueryString["cache"] = ServerCacheMode.Always.ToString();
Logger.Error("ImageResizer Process: " + context.Request.RawUrl);
}
There are no warnings or errors in the debug trace, and I receive a 404 when I expect the image to be returned.
Upvotes: 0
Views: 180
Reputation: 16468
Amazon S3 suggests using the subdomain address method to ensure optimal performance for non-US regions - which is what S3Reader does by default (and which you have also enabled).
As such, your bucket name can't have periods or leading dashes (but you can have embedded dashes).
Assuming the value of AmazonS3BucketName is "media.domain.com", this would be the reason for the image lookup failure.
See Notes on bucket naming at the bottom of the S3Reader plugin documentation page.
Upvotes: 2