Masking real URL serving images with best possible performance in MVC

23 views Asked by At

There are a couple of problems I'm trying to solve with this question, but the main one is the company I work for is currently using a third party service to host our images because it allows us us to modify resolution, watermarks, and various other features on the fly by modifying the query strings.

The main reason I cannot use the real URL directly is it would give scrapers and other people the ability to steal our images (which we put a lot of time and money into) without any of our logos and to more easily download the list of images by guessing the filenames without having to even visit the product pages.

I have considered writing a service our website can connect to that can better cache, save locally, and handle these requests, but I feel like the ideal way would be to be able to connect the client too the third party through some sort of web socket, proxy, or tunnel that can asynchronously read and write the stream back to the client instead of doing it one step at a time. However, I am unsure what would be the best .NET classes to use to accomplish this while also still hiding the third party end point. I was considering trying to use a custom HttpHandler class, but I'm not even sure that will work. Ideally I would like to be able to do it directly from the controller if possible for simplicities sake, but I know there are limitations there as well. So I was just curious if anyone had any suggestions on what I should read or look into to go about this. Of course any example code would be awesome, however I have been a developer for almost 15 years so even being pointed in the right direction would be a huge help. I am sorry this is so long and any suggestions would be greatly appreciated. Thank you for your time if you've made it this far.

If you are looking for a shorter sample of what I'm trying you do. Imagine using a browser to connect to https://www.web.com/image.png and having it return https://www.otherweb.com/otherimage.png without the client knowing it's hitting the second endpoint while also doing it as fast as possible.

Our current implementation is to have a route on our MVC application that goes and downloads the desired image using the real URL then returns it to the client. This way the client doesn't see the real URL, but this is obviously far from the best way to do it from a performance standpoint because of the latency from downloading the image initially. Yes, we are using a CDN that points to the MVC route that does help and we also use some simple caching as well to help alleviate this problem, but I would still would like to try to achieve something better.

0

There are 0 answers