diff --git a/amazons3/AmazonS3StreamWrapper.inc b/amazons3/AmazonS3StreamWrapper.inc
index be0e0a2..c1c3c36 100644
--- a/amazons3/AmazonS3StreamWrapper.inc
+++ b/amazons3/AmazonS3StreamWrapper.inc
@@ -195,13 +195,19 @@ class AmazonS3StreamWrapper implements DrupalStreamWrapperInterface {
     if(count($modes) != 3) {
       return FALSE;
     }
-    
+	
+	// Add handling of S3 directory structure
+    $localpath = $this->getLocalPath();
+	if ($this->_is_dir($localpath)){
+	 $localpath = $localpath . '/';
+	}
+	
     if(intval($modes[2]) >= 4) {
-      $response = $this->getS3()->set_object_acl($this->bucket, $this->getLocalPath(), AmazonS3::ACL_PUBLIC);
+      $response = $this->getS3()->set_object_acl($this->bucket, $localpath, AmazonS3::ACL_PUBLIC);
       return $response->isOK();
     }
     else {
-      $response = $this->getS3()->set_object_acl($this->bucket, $this->getLocalPath(), AmazonS3::ACL_PRIVATE);
+      $response = $this->getS3()->set_object_acl($this->bucket, $localpath, AmazonS3::ACL_PRIVATE);
       return $response->isOK();
     }
     