<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>image resizer Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/tag/image-resizer/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/tag/image-resizer/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 10 Jan 2019 12:46:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Azure CDN, BlobStorage and ImageResizer</title>
		<link>https://blogit.create.pt/andresantos/2015/06/26/azure-cdn-blobstorage-and-imageresizer/</link>
					<comments>https://blogit.create.pt/andresantos/2015/06/26/azure-cdn-blobstorage-and-imageresizer/#comments</comments>
		
		<dc:creator><![CDATA[André Santos]]></dc:creator>
		<pubDate>Fri, 26 Jun 2015 15:48:38 +0000</pubDate>
				<category><![CDATA[CDN]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[azure]]></category>
		<category><![CDATA[azurereader2]]></category>
		<category><![CDATA[blob storage]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[feature receiver]]></category>
		<category><![CDATA[image resizer]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[mvc 5]]></category>
		<category><![CDATA[sharepoint]]></category>
		<guid isPermaLink="false">http://blogit.create.pt/andresantos/?p=371</guid>

					<description><![CDATA[<p>In a recent project, we had the need to serve website assets and website content images through a CDN network. Furthermore, each image presented in the website content must be available in multiple resolutions. We ended up serving both the assets and content images through the same Microsoft Azure CDN. This post describes the way we [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/andresantos/2015/06/26/azure-cdn-blobstorage-and-imageresizer/">Azure CDN, BlobStorage and ImageResizer</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span class="dropcap dropcap3">I</span>n a recent project, we had the need to serve website assets and website content images through a CDN network. Furthermore, each image presented in the website content must be available in multiple resolutions.</p>
<p>We ended up serving both the assets and content images through the same Microsoft Azure CDN. This post describes the way we implemented it.</p>
<p>First the easiest part. We have our site in a Azure Website, in order to serve the site&#8217;s assets through an Azure CDN we only needed to point the CDN to the website&#8217;s URL. So, if the website&#8217;s assets are located in something like <em>http://sitedomain/assets/*</em>, instead of referencing the assets through a relative url such as <em>/assets/*</em>, we just need to use the CDN url to serve them: <em>http://cdnurl/assets/*</em>. Through web.config transforms we are also able to use local assets during development and change to CDN only on the production environment.</p>
<p>Regarding the website image content, the solution has three phases.</p>
<p><span id="more-6465"></span></p>
<p><strong>1.</strong> The content is managed over SharePoint 2013, and the images are no exception. We created a feature receiver that uploads to Azure Blob Storage every time an image is uploaded, or modified,  on any Picture Library, and then save its known CDN URL in the library item.</p>
<pre class="brush: csharp; title: ; notranslate">
string cdnUrl = Configuration.Settings.ImageUploader.CdnUrl;
string containerStr = Configuration.Settings.ImageUploader.Container;

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting(IMAGES_STORAGE_CONNECTION_STRING));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference(containerStr);

// Creates the container if it doesn't exist
container.CreateIfNotExists();

// Set the blobs access level to public
container.SetPermissions(new BlobContainerPermissions
{
    PublicAccess = BlobContainerPublicAccessType.Blob
});

string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.Name);
string extension = Path.GetExtension(file.Name);

fileNameWithoutExtension += &quot;-&quot; + DateTime.Now.Ticks;

// Build file name to upload
string fileName = string.Format(&quot;{0}/{1}{2}&quot;, file.Item.ParentList.Title.ToLower(), fileNameWithoutExtension.Replace(&quot; &quot;, &quot;-&quot;), extension).ToLower();

// Retrieve reference to a blob named &quot;file.name&quot;.
CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);

// Create or overwrite the &quot;file.name&quot; blob with contents from a local file.
using (var fileStream = file.OpenBinaryStream())
{
    blockBlob.UploadFromStream(fileStream);

    // Update SP item CDN URL column
    string finalUrl = HttpUtility.UrlPathEncode(string.Format(&quot;{0}/{1}/{2}?{3}&quot;, cdnUrl, containerStr, fileName, IMAGE_RESIZER_FIRST_PARAMETER));

    properties.ListItem&#x5B;Configuration.Settings.SP_COLUMN_CDN_URL] = finalUrl.ToLower();
    properties.ListItem.SystemUpdate(false);
}
</pre>
<p><strong>2.</strong> Having the images in a Azure Blob Storage, we decided to use the <a title="Image Resizer ASP.NET Library and Image Server" href="http://imageresizing.net/" target="_blank" rel="noopener">Image Resizer ASP.NET Library</a> and its <a title="AzureReader2 BlobStorage Plugin" href="http://imageresizing.net/docs/v4/plugins/azurereader2" target="_blank" rel="noopener">AzureReader2 plugin</a> to resize and serve images directly through our Azure Website. The implementation is as easy as installing a nuget package: Image Resizer. After configuring the Blob Storage endpoint, and setting the prefix (we use ~/azure), we are able to access the images through an URL such as: <em>http://sitedomain/azure/image/path/in/blobstorage</em>. With this working we can resize and modify the images in any way available to us with the Image Resizer library and described in detail here: <a title="http://imageresizing.net/docs/v4" href="http://imageresizing.net/docs/v4" target="_blank" rel="noopener">http://imageresizing.net/docs/v4</a>.</p>
<p><strong>3.</strong> Since our CDN is pointing directly to our Azure Website, we can use the CDN URL instead of the azure website one. For instance, the fake image I talked about the previous bullet can be accessed with the following URL: <em>http://cdnurl/azure/image/path/in/blobstorage</em>. This way, the first time someone opens an image through the CDN URL it is handled by the Image Resizer library. The  second time, CDN has already cached it and distributed it around the world and it is served much faster!</p>
<p>The post <a href="https://blogit.create.pt/andresantos/2015/06/26/azure-cdn-blobstorage-and-imageresizer/">Azure CDN, BlobStorage and ImageResizer</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/andresantos/2015/06/26/azure-cdn-blobstorage-and-imageresizer/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
