I was asked about listing everything in a DreamObjects bucket, which is practically the same thing as listing everything in an Amazon S3 bucket, just on a different server.
This isn’t as easy as we’d like, because while there is a nice Amazon S3 PHP class we can use (and I forked it and flipped it to be a DreamObjects PHP Class), telling people they have to download the S3.php file and then make this separate PHP file is a little annoying.
//include the S3 class if (!class_exists('S3'))require_once('S3.php'); //AWS access info if (!defined('awsAccessKey')) define('awsAccessKey', 'MYACCESSKEY'); if (!defined('awsSecretKey')) define('awsSecretKey', 'MYSECRETKEY'); //Bucket Info $bucketName = 'MYBUCKETNAME'; /* STOP EDITING HERE */ //instantiate the class $s3 = new S3(awsAccessKey, awsSecretKey); // Get the contents of our bucket $bucket_contents = $s3->getBucket($bucketName); foreach ($bucket_contents as $file){ $fname = $file['name']; $furl = 'http://'.$bucketName.'.objects.dreamhost.com/'.$fname; //output a link to the file echo '<a href=\'$furl\'>$fname</a><br />'; }
I know, it’s not too terribly complicated, but it is annoying to make two files for that, and my DreamObjects listing page is very barebones. You could style it with CSS, make it show the image, make it show in a grid, or even show the file size and have it pop up in a new window.
It does highlight one of my issues with CEPH (AWS whatever) storage, and that it’s still not quite friendly enough. It dumps us back to the old days where we FTP’d our images up to a server and then manually crafted our links. Certainly there are plugins for WordPress that can help us with that, but in general it requires knowing code (or where to get the code) in order to display content.
Comments
6 responses to “Listing Everything on DreamObjects”
I had to do some research to figure out what this post is about. It looks like you guys have created some sort of alternative to S3, with a compatible API.
I’m not sure how compatible your API is, but there are ways to mount S3 drives. If you could do that, then you could treat them as part of a regular old local drive and not require any messing around with PHP.
I use the CLI tool S3CMD quite extensively. It’s a nifty little thing that lets you shunt data to and fro from S3 without any of the problems associated with doing it in PHP (memory limits in particular are easily hit in PHP, but in general I don’t think PHP is anything like as reliable as doing this stuff directly from a the CLI). I have no idea if it works with non-S3 CEPH systems though.
Related: A little warning about storing API credentials inside PHP files … http://wptavern.com/ryan-hellyers-aws-nightmare-leaked-access-keys-result-in-a-6000-bill-overnight
@Ryan Hellyer: Sorry, yes, DreamObjects is DreamHost’s AWS. It’s not super obvious how it all works though. Not even AWS. It’s just not super newbie friendly yet.
And yeah, I did see that ‘leak.’ I’ve had a pre-defined reply to plugin devs who do that for. While π
@Ipstenu (Mika Epstein): What sort of response would you have to plugin devs. who do that? I assumed it’s acceptable in the repository, since there’s no other way to do it.
@Ryan Hellyer: Well mostly it’s “For God’s sake don’t hardcode your API keys in!”
Yeah. They do.
Ah, you mean putting API keys inside plugin files? If so, then yeah, that’s bound to be against the repository guidelines. My plugin didn’t do that. It included the API keys outside of the WordPress folder altogether, but due to an error on my part I accidentally put them into my site root and uploaded them to GitHub.
@Ryan Hellyer: That’s something I can’t ever see us disallowing. After all, I have my WPCOM API key in my wp-config.php file. I also have that file a folder up and I don’t sync it, but … well you can’t outlaw mistakes π