c# - Resizing / caching JPEG images on Azure -


i have website written in .net 4.5 / mvc 4 allows users upload images, among other things. these images can displayed throughout site in variety of sizes. currently, way works follows:

  • the image uploaded , re-sized in memory max width of 640px (the largest site display).
  • the resized image saved disk @ /assets/photos/source/{id}-{timestamphash}.jpg.
  • when request image in various sizes comes through, filename combining {id}-{hash} {hash} hash of combination of ids, height, width , other information need image.
  • if image exists in /assets/photos/cache, return it, otherwise create in memory using source image , save cache directory.

i approach because happens , happens in-memory or via disk retrieval.

i'd move site azure. how workflow happen in azure given of images stored blobs? still efficient use re-sizing/caching strategy or there other alternatives? wouldn't incur network latency image uploaded azure server today, gets saved disk lot faster?

just looking direction on how migrate workflow workable , scalable azure.

given comment above, why not create background task resizes acceptable sizes on upload, storing each 1 azure blob storage. correct if resize on request, suffer latency , lag need download source image, resize, upload blob storage, redirect user blob storage url. given 'cheapness' of blob storage, submit paying few dimes more storage outweight potential slowness of scenario above.

pseudo code below:

[httppost] public actionresult fileupload(httppostedbasefile file){    if(validatefile(file)){       //fire off background tasks resizes , stores each file size azure       //blog storage.  use naming scheme such id_size.imagetypeextension    }  } 

now, when asked file, still use same routine, instead of returning file result, return redirect result

public actionresult getimage(string hash){     //do stuff image details     return redirect("http://yourazureblobstoragedomain.com/assets/images/cache/" + imagedetails") } 

this cool because don't need download image web server , serve it, redirect request directly blob storage! have affect image tag such below

<img src="@url.routeurl("getimage", "images" new {hash = hash})"/> hit web application, forcing redirect actual image location in blob storage.

you correct not want store on azure web role permanently web roles can moved around @ time, losing locally stored data.

this simple way sort of keep code base way minimal changes. modify behave more have in query blob storage if image exists, if does, redirect, if not generate, store , redirect, believe find have more issues latency @ point given need download source image, stuff , reupload image before instructing user's browser go find it.

however, decide if worth time take resize on demand vs cost of storing multiple sizes of each image. side note, have not noticed significant latency issue when using blob storage our web/worker roles. higher retrieval disks, has not posed significant increase have been able see.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -