I've been using ImageResizer.net just fine in our web app, but now I need it to resize and serve images that don't (and cannot) have a file extension, like this one:
http://localhost:58306/ClientImages/Batch/2012/12/10/f45198b7c452466684a4079de8d5f85f?width=600
In this situation, I know that my files are always TIFF's, but they wont have a file extension.
What are my options?
/resizer.debug.ashx: https://gist.github.com/raw/9c867823c983f0e5be10/4db31cb21af8b9b36f0aa4e765f6f459ba4b309f/gistfile1.txt
Update
I followed Computer Linguist's instructions:
protected void Application_Start()
{
Config.Current.Pipeline.PostAuthorizeRequestStart +=
delegate
{
var path = Config.Current.Pipeline.PreRewritePath;
var clientImgsRelPath = PathUtils.ResolveAppRelative("~/ClientImages/");
var isClientImageRequest = path.StartsWith(clientImgsRelPath, StringComparison.OrdinalIgnoreCase);
if (isClientImageRequest)
Config.Current.Pipeline.SkipFileTypeCheck = true;
};
// other app start code here
}
http://localhost:58306/ClientImages/Batch/2012/12/10/92d67b45584144beb5f791aaaf760252?width=600 just responds with the original image with no resizing.
This was also asked about here: http://imageresizing.net/docs/howto/cache-non-images#comment-571615564
This is happening during development with the Cassini or Visual Studio web server or whatever you want to call it.
First, you MUST be using IIS7 Integrated mode. Classic mode will not work; it does not permit ASP.NET access to extensionless requests
ImageResizer can't know that extension-less URLs are images unless you explicitly tell it.
This doc explains:
http://imageresizing.net/docs/howto/cache-non-images
Essentially, you'll end up performing logic (usually String.StartsWith) on your URLs to find out if ImageResizer should treat the file as an image.
Config.Current.Pipeline.PostAuthorizeRequestStart += delegate(IHttpModule sender, HttpContext context) {
string path = Config.Current.Pipeline.PreRewritePath;
//Skip the file extension check for everything in this folder:
if (path.StartsWith(PathUtils.ResolveAppRelative("~/folder/of/images"),
StringComparison.OrdinalIgnoreCase)){
Config.Current.Pipeline.SkipFileTypeCheck = true;
}
};
You should register this event handler in Application_Start in global.asax.
Related
i'm building a project on Xamarin. Right now i have a big issue. I need to browse user's computer for upload any file. He can of course upload multiple files. As i know Xamarin does not provide browsing of all the system but just its. So i tried to find a way with some drag n drop, i didn't find. I tried a filepicker but he let me pick just one file (my client would upload 100 files at once) so it doesn't fit to what i need. Finally i decided to do my own browsing system but it takes forever to browse because of the UI. Do you have any solution for me ? I would appreciate a package with a filepicker that allow multiple files.
Thanks
Have you tried the class FileOpenPicker in UWP ?
It supports to pick multiple files , check the method FileOpenPicker.PickMultipleFilesAsync.
Sample
Define interface in Forms project
public interface MyFilePicker
{
Task OpenFilePickerAsync();
}
Implement in UWP project
[assembly: Dependency(typeof(UWPFilePicker))]
namespace App24.UWP
{
class UWPFilePicker : MyFilePicker
{
public async Task OpenFilePickerAsync()
{
var openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();
if (files.Count > 0)
{
StringBuilder output = new StringBuilder("Picked files:\n");
// Application now has read/write access to the picked file(s)
}
else
{
return;
}
}
}
}
Call it in Forms project
private async void Button_Clicked(object sender, EventArgs e)
{
MyFilePicker service = DependencyService.Get<MyFilePicker>();
await service.OpenFilePickerAsync();
}
I am using the CrossDownManager plugin for Xamarin Forms
Here
When I run the method on Android it processes as expected. On iOS Debug.Writeline("Success!") isn't being hit like it was on Android.
Here is the code:
void ViewImage(string imageLink)
{
var downloadManager = CrossDownloadManager.Current;
downloadManager.PathNameForDownloadedFile = new System.Func<IDownloadFile, string>(file =>
{
string path = DependencyService.Get<IImageSaver>().Save("YHTS" + DateTime.Today.Ticks.ToString() + ".jpg");
Debug.WriteLine("Success!");
return path;
});
try
{
var file = downloadManager.CreateDownloadFile(imageLink);
Debug.WriteLine("file created");
downloadManager.Start(file);
Debug.WriteLine("downloadstarted");
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}
For the life of me I can't figure out why the that code block isn't processed. Any ideas?
This is an interesting issue as technically your code should work as expected. I've done a little digging and found a reply to a similar question here.
your options are many... including:
DEBUG preprocessor as you show in your question.
Use System.Diagnostic.Debug.WriteLine: Any calls to Debug.* will be
removed by the compiler due to the [Conditional("DEBUG")] attribute
being applied.
Create your own "Logger" class as a wrapper to the stdout writers and
[Conditional("DEBUG")] it
Use Fody and re-weave the assemblies to remove/NOP/redirect the
WriteLine I do this to redirect the calls to in internal log and upon
crash or user stat requests, forward this log to our crash reporting
servers. etc, .....
So there are a few alternatives to consider, one of the common suggestions I've seen is to use the fully qualified reference for WriteLine(); as such:
System.Console.WriteLine("woop woop");
I would suggest giving the above a try first.
I am including a big javascript application into our MVC-based solution. However, the application includes a lot of files due to which I would like to enable bundling and minification on it. In fact, I would like to enable bundling on all 3rd party javascript and CSS files while keeping the files we develop ourselves unminified and unbundled. Until release, of course.
There is way to enable optimizations globally:
public static void RegisterBundles(BundleCollection bundles)
{
Bundle ckScripts = new ScriptBundle("~/scripts/ckeditor")
.IncludeDirectory("~/Areas/CMS/Editor", "*.js", true);
bundles.Add(ckScripts);
BundleTable.EnableOptimizations = true;
}
However, this happens in the top BundleTable level enabling optimizations on all the bundles within the bundle table.
I would need to have something like this:
public static void RegisterBundles(BundleCollection bundles)
{
Bundle ckScripts = new ScriptBundle("~/scripts/ckeditor")
.IncludeDirectory("~/Areas/CMS/Editor", "*.js", true)
.EnableOptimizations();
bundles.Add(ckScripts);
}
Which would effectively enable optimizations only for that particular bundle.
I know, there is currently no Bundle.EnableOptimizations() method and creating such given the fact that the optimization happens in the BundleTable level, which is inherently global by design, creating such method, would prove very difficult.
So, here I in loss of ideas where to look into.
Questions:
Is there an alternative framework somewhere that would support this
Is there a contrib project somewhere that would provide this
Have you encountered such need, possibly have a solution
Provided that there's no existing solution, please post an idea how to start unfolding this challenge.
From what I know, BundleTable is a singleton. Which means there can be only one instance. I had an idea of creating another bundle table but got lost when I started figuring out how to make MVC use it.
Another starting point would be to code a custom renderer. One that mimics the behavior of System.Web.Optimization.Scripts.Render(), but again, I'm getting lost with it trying to figure out in which state the BundleTable comes into picture.
UPDATE
Seems like I can create a new BundleContext and BundleResponse by using a HtmlHelper.
public static IHtmlString RenderBundled<TSource>(this HtmlHelper<TSource> helper, string bundlePath)
{
// Find the bundle in question
var bundle = BundleTable.Bundles.FirstOrDefault(b => b.Path == bundlePath);
// No bundle found, return
if (bundle == null) return MvcHtmlString.Create(String.Empty);
// Add the bundle found into a new collection
BundleCollection coll = new BundleCollection {bundle};
// Create a new BundleContext
BundleContext ctx = new BundleContext(helper.ViewContext.HttpContext, coll, "~/bundles");
// Enable optimizations
ctx.EnableOptimizations = true;
// Create the response (this contains bundled & minified script/styles from bundle)
BundleResponse response = bundle.GenerateBundleResponse(ctx);
// Render the content based on ContentType
if (response.ContentType == "text/css")
return RenderStyle(response.Content);// returns <style>bundled content</style>
if (response.ContentType == "text/javascript")
return RenderScript(response.Content); // returns <script>bundled content</script>
// In any other case return "nothing"
return MvcHtmlString.Create(String.Empty);
}
This probably is not the best approach. Overhead from creating BundleContext on every page request and adding the script/styles payload into the page output without the caching abilities. But it's a start. One thing I noticed was that the bundled content will actually be cached in HttpContext.Cache. So, theoretically I could just put the bundle path into script src or style href and somehow then handle the request from server side.
I have a quick question here. Can any one please help me to sort out this problem.
I'm new to windows Phone. I'm developing an Application where i can change my Font styles for the entire application . I have three different Resource file to set three different types of font styles. The resource file are set to application in App.xaml.cs file. Now i need to support to change the styles in Application run time from Application Changestyles page. So i need to call the method in app.xaml.cs from changestyles.xaml.cs page.
private void LoadResourceDictionary()
{
var dictionaries = new ResourceDictionary();
string source = String.Format("/Testapp;component/Large.xaml");
var themeStyles = new ResourceDictionary { Source = new Uri(source, UriKind.Relative) };
dictionaries.MergedDictionaries.Add(themeStyles);
App.Current.Resources = dictionaries;
ResourceDictionary appResources = App.Current.Resources;
}
I need to call this method to set the another resource to my application in run time.
Is it possible to resolve this issue?
Make this method public static and you can call it from everywhere: App.LoadResourceDictionary();
Here is a generic how to based on the code I needed for an app I am writing. I know the circumstances are slightly different, but it may help someone else who is after a similar solution:
In MainPage.xaml you create a method as follows:
public static void InMainPage()
{
System.Diagnostics.Debug.WriteLine("Hi I am a method in MainPage.xaml.cs");
}
Now in App.xaml.cs you can call it in any method as such:
MainPage.InMainPage();
AND IT WORKS FOR YOU CIRCUMSTANCE IN THE REVERSE DIRECTION
In App.xaml.cs you create a method as follows:
public static void InAppXaml()
{
System.Diagnostics.Debug.WriteLine("Hi I am a method in App.xaml.cs");
}
Now in Mainpage.xaml.cs you can call it in any method as such:
App.InAppXaml();
Tested and works well. Hope it helps!
public string AsyncUpload()
{
return _fileStore.SaveUploadedFile(Request.Files[0]);
}
in the SaveUpload
private string _uploadsOriginalFolder = HostingEnvironment.MapPath("~/Content/Images/OriginalImages");
private string _uploadsThumbnailFolder = HostingEnvironment.MapPath("~/Content/Images/Thumbnails");
var identifier = Guid.NewGuid();
var originalFileNameToSave = identifier.ToString() +".jpg" ;
fileBase.SaveAs( Path.Combine(_uploadsOriginalFolder, originalFileNameToSave));
imagingService.ResizeImage(Path.Combine(_uploadsOriginalFolder, originalFileNameToSave),
Path.Combine(_uploadsThumbnailFolder,originalFileNameToSave),
160,
120,
false);
return originalFileNameToSave;
I want to have Domain.Com/Thumbnails/guid.jpg and Domain/OriginalImages/guid.jpg
i want this to be stored on to a \dfs.domain.com\Scanning[project]\Images directory.
how do i save it to that location and what rights do i need to provide on it.
has any body done this before. i guess many?
You can store the image wherever you want on your server as long as you provide write permissions to that folder. Obviously if you want to access it from another ASP.NET application you can no longer use relative paths. So if the dfs.domain.com site root is physically mapped toc:\foobar you could save the file as absolute path at c:\foobar\Scanning[project]\Images folder. The MVC application that is saving the file has no way of knowing how is this other site configured so you could externalize the other site root path at your web.config.
The best is to map phisical path to virtual folder in iis, and then allow write permisson on it. This is how I done when I have multiple web apps, which are using same folder for static content.