<?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>Floorplanner Tech Blog &#187; S3</title>
	<atom:link href="http://techblog.floorplanner.com/tag/s3/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.floorplanner.com</link>
	<description>Our latest geek adventures!</description>
	<lastBuildDate>Tue, 16 Mar 2010 18:45:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Generating thumbnails</title>
		<link>http://techblog.floorplanner.com/2008/11/26/generating-thumbnails/</link>
		<comments>http://techblog.floorplanner.com/2008/11/26/generating-thumbnails/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 06:27:05 +0000</pubDate>
		<dc:creator>Willem van Bergen</dc:creator>
				<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[client-side]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[S3]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=271</guid>
		<description><![CDATA[I would like to thank you all for helping us build our thumbnail database!  I presume this statement might be in need of some clarification, so bear with me when I go into the technical details on this one.
For every design that is saved on Floorplanner, we create a thumbnail in JPEG format. We [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to thank you all for helping us build our thumbnail database! <br /> I presume this statement might be in need of some clarification, so bear with me when I go into the technical details on this one.</p>
<p>For every design that is saved on Floorplanner, we create a thumbnail in JPEG format. We use these thumbnails for the <a href="http://beta.floorplanner.com/gallery">gallery</a>, and now we have included them on everyone&#8217;s <a href="http://beta.floorplanner.com/dashboard">dashboard</a>. However, for various reasons, we do not have a thumbnail available for every design. However, with your help, we are improving the thumbnail database while you our browsing the site!</p>
<p>The thumbnail images are stored on <a href="http://aws.amazon.com/s3/">Amazon AWS S3</a>. We know the URL that a thumbnail of a design should have, but we do not know if it actually is available. In the latter case, the result is a nasty <em>image not found</em> placeholder on the dashboard. This of course is not acceptable! We cannot know if a thumbnail exists other than doing a request to the URL and see whether we get an image back from Amazon, or a HTTP 404 status. This is a very time-consuming procedure to run server side so we chose to find a client-side solution.</p>
<p>We found that javascript can be used to check if an image exist. An AJAX call cannot be used, because cross-site calls are not supported. However, the javascript <code>Image</code> object <em>can</em> be used for this purpose.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family: Monaco,monospace;"><span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
img.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// image was found and loaded successfully</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img-tag'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> img.<span style="color: #660066;">src</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
img.<span style="color: #000066;">onerror</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// An error occured while loading the image</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img-tag'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/images/thumb-unavailable.jpg'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Setting the src property will trigger the events.</span>
img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://link.to.amazon.s3/design/thumbnail.jpg'</span><span style="color: #339933;">;</span></pre></div></div>

<p>A nice <em>thumbnail not available</em> image will be shown if the thumbnail file cannot be found on S3. This is much nicer, and the check is completely done client-side! However, we found a way this could even be better by changing the <code>onerror</code> event handler. Instead of displaying a <em>thumbnail not available</em> image, we can simply load a small instance of the Floorplanner application to display a small version of the design. Moreover, we can instruct it to generate a thumbnail JPEG and save it to S3!</p>
<p>So, every time you see a small Floorplanner loading on your dashboard, you are creating a missing thumbnail. Next time, the thumbnail will be available on S3 and there will be no need to start the Floorplanner application. A nice example of <a href="http://en.wikipedia.org/wiki/Distributed_computing">distributed computing</a>, mixed with a hint of <a href="http://setiathome.berkeley.edu/">SETI@home</a>. I like it!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/11/26/generating-thumbnails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
