<?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>kill the radio &#187; s3</title>
	<atom:link href="http://blog.killtheradio.net/tag/s3/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.killtheradio.net</link>
	<description>or die trying</description>
	<lastBuildDate>Thu, 15 Dec 2011 20:21:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Is a good Windows-based S3 tool too much to ask?</title>
		<link>http://blog.killtheradio.net/technology/is-a-good-windows-based-s3-tool-too-much-to-ask/</link>
		<comments>http://blog.killtheradio.net/technology/is-a-good-windows-based-s3-tool-too-much-to-ask/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 19:20:08 +0000</pubDate>
		<dc:creator>Andrew Lyon</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[s3]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.killtheradio.net/?p=77</guid>
		<description><![CDATA[With Amazon S3 being as good and cheap as it is, it&#8217;s almost essential for what I need it for&#8230;storing images and large static files. The problem is there is no interface besides SOAP, and if you don&#8217;t know how I feel about SOAP, let me tell you: it makes my head want to fucking [...]]]></description>
			<content:encoded><![CDATA[<p>With Amazon S3 being as good and cheap as it is, it&#8217;s almost essential for what I need it for&#8230;storing images and large static files. The problem is there is no interface besides SOAP, and if you don&#8217;t know how I feel about SOAP, let me tell you: it makes my head want to fucking explode. It&#8217;s insanely complicated for what it does. It tries to standardize so many things that it&#8217;s completely bloated&#8230;sending the message &#8220;hello&#8221; from one computer to another in SOAP takes oh about 10 years&#8230;5 years for a team of 50 supercomputers working in tandem to build the header and message body (which will total about 400 mb when finally complete), .02ms to send, and 5 years in decoding. Use JSON, you crackheads. Sure you&#8217;ll actually have to document it, but nothing is worse than SOAP, not even documenting.</p>
<p>That&#8217;s besides the point though. S3 chose to use SOAP, so I refuse to write my own client for it. This means that, as of late, the world is without a <span style="text-decoration: underline;">good</span> free S3 uploading client. S3Fox, the firefox extension, is ok&#8230;it can&#8217;t handle SSL connections though, so expect to lose your private key to a sniffer about 10 seconds after your first request. JungleDisk is now a completely paid service (I already pay for S3, I&#8217;m not paying those guys to fucking USE it). Linux has some great <em>command line</em> tools for S3 (yay&#8230;), but that leaves windows with either S3fox, JD ($$$), or a handful of shitty S3 clients.</p>
<p>Right now, I have to use a PHP script I built around the <a href="http://undesigned.org.za/2007/10/22/amazon-s3-php-class" target="_blank">S3 PHP Class</a> to do any uploading that doesn&#8217;t make me vomit. The S3 class works REALLY well&#8230;it lets you assign ACL while uploading, change headers for images (for browser-side caching, mmm) and best of all, doesn&#8217;t completely suck. Let&#8217;s all thank Donovan Schönknecht for writing something that actually works well and communicates with S3.</p>
<p>Here&#8217;s a piece of code I wrote that wraps around the S3 uploader. It uploads images, sets Cache-Control headers, and removes the images. What you want to do is copy your images into a folder, run this file one directory up (change $start_folder to == the name of the folder your images are in), and sit back. It will upload all your images, directory structure preserved, publicly viewable and with cache-control headers.</p>
<pre>&lt; ?
	// quick config
	$bucket			=	'your.bucket.com';
	$start_folder	=	'images';

	// settings
	error_reporting(E_ALL);
	ini_set('display_errors', 1);
	ini_set('max_execution_time', 3600);

	// include S3 class
	include 'S3.php';
	$s3	=	new S3('[your key]', '[your secret]', false);

	// get list of files. if you don't want a subdirectory, just change this line to not need one. hopefully you know PHP...
	$files	=	recurse(array(), $start_folder);

	// loop over files and upload
	for($i = 0, $n = count($files); $i &lt; $n; $i++)
	{
		$ext	=	preg_replace('/.*\./', '', $files[$i]);
		$type	=	'image/jpeg';
		if($ext == 'jpg')
		{
			$type	=	'image/jpeg';
		}
		else if($ext == 'gif')
		{
			$type	=	'image/gif';
		}
		else if($ext == 'png')
		{
			$type	=	'image/png';
		}

		if(
			!$s3-&gt;putObject(
				$s3-&gt;inputFile($files[$i]),
				$bucket,
				$files[$i],
				S3::ACL_PUBLIC_READ,
				array(),
				array('Cache-Control' =&gt; 'max-age=31536000', 'Content-Type' =&gt; $type)
			)
		)
		{
			echo '&lt;span style="color:green;"&gt;Failed: upload of '. $files[$i] . '';
		}
		else
		{
			echo '&lt;span style="color:green;"&gt;Succeeded: upload of '. $files[$i] .'';
			unlink($files[$i]);
		}
	}

	function recurse($files, $dir)
	{
		$d	=	scandir($dir);

		for($i = 0, $n = count($d); $i &lt; $n; $i++)
		{
			if(!preg_match('/^\./', $d[$i]))
			{
				if(is_dir($dir . '/' . $d[$i]))
				{
					$files	=	recurse($files, $dir . '/' . $d[$i]);
				}
				else
				{
					$files[]	=	$dir . '/' . $d[$i];
				}
			}
		}

		return $files;
	}
?&gt;</pre>
<p>Feel free to modify, copy, blah blah&#8230;but give credit where it&#8217;s due. Let it be a light to you when all other lights go out. Hopefully it helps someone, because it sure helps me out.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.killtheradio.net/technology/is-a-good-windows-based-s3-tool-too-much-to-ask/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

