| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Amazon S3 storage driver for filesystem. |
* Amazon S3 storage driver for fileapi. |
| 6 |
* |
* |
| 7 |
* We are treating S3 like a normal hierarchal filesystem. The bucket |
* We are treating S3 like a normal hierarchal filesystem. The bucket |
| 8 |
* is predetermined by the mountpoint settings. Except for list buckets |
* is predetermined by the mountpoint settings. Except for list buckets |
| 9 |
* and put bucket functions. |
* and put bucket functions. |
| 10 |
* |
* |
| 11 |
* We use the keys with a delimiter of '/' to create our heirarchy. |
* We use the keys with a delimiter of '/' to create our heirarchy. |
| 12 |
|
* |
| 13 |
|
* @todo examine adding caching to save some requests to S3. |
| 14 |
* |
* |
| 15 |
*/ |
*/ |
| 16 |
|
|
| 86 |
*/ |
*/ |
| 87 |
function fileapi_driver_s3_is_file($settings, $path) { |
function fileapi_driver_s3_is_file($settings, $path) { |
| 88 |
// request meta data for an object with the key $path. |
// request meta data for an object with the key $path. |
| 89 |
$result = s3_request('HEAD', $path, $settings); |
$result = s3_request('HEAD', $settings['bucket'] .'/'. $path, $settings); |
| 90 |
|
|
| 91 |
//parse results for request... |
//parse results for request... |
| 92 |
} |
} |
| 166 |
$headers = array(); |
$headers = array(); |
| 167 |
$headers['Content-Type'] = 'text/plain'; |
$headers['Content-Type'] = 'text/plain'; |
| 168 |
$body = file_get_contents($tmp); |
$body = file_get_contents($tmp); |
| 169 |
s3_request('PUT', $path, $settings, array(), $body); |
$result = s3_request('PUT', $path, $settings, array(), $body); |
| 170 |
|
$xml = SimpleXMLElement($result['data']); |
| 171 |
unlink($tmp); |
unlink($tmp); |
| 172 |
} |
} |
| 173 |
|
|
| 180 |
* action results and array of directory contents. |
* action results and array of directory contents. |
| 181 |
*/ |
*/ |
| 182 |
function fileapi_driver_s3_readdir($settings, $path) { |
function fileapi_driver_s3_readdir($settings, $path) { |
| 183 |
$result = s3_request('GET', $settings['bucket'] .'?delimiter=/&key=$path', $settings); |
// $result = s3_request('GET', $settings['bucket'] .'?delimiter=/&key=$path', $settings); |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
/** |
/** |
| 192 |
* and our support target is 4.3.0. |
* and our support target is 4.3.0. |
| 193 |
*/ |
*/ |
| 194 |
function fileapi_driver_s3_fileread($settings, $path) { |
function fileapi_driver_s3_fileread($settings, $path) { |
| 195 |
$result = s3_request('GET', $path, $settings); |
// $result = s3_request('GET', $path, $settings); |
| 196 |
return $result; |
return $result; |
| 197 |
} |
} |
| 198 |
|
|
| 199 |
function fileapi_driver_s3_filewrite($settings, $path, $data) { |
function fileapi_driver_s3_filewrite($settings, $path, $data) { |
| 200 |
$headers = array('Content-Type' => 'text/plain'); |
$headers = array('Content-Type' => 'text/plain'); |
| 201 |
$result = s3_request('PUT', $settings['bucket'] .'/'. $path, $settings, array(), $data); |
// $result = s3_request('PUT', $settings['bucket'] .'/'. $path, $settings, array(), $data); |
| 202 |
return $result; |
return $result; |
| 203 |
} |
} |
| 204 |
|
|
| 208 |
|
|
| 209 |
// Set date to proper format for S3. |
// Set date to proper format for S3. |
| 210 |
$headers['Date'] = gmdate(DATE_RFC822); |
$headers['Date'] = gmdate(DATE_RFC822); |
| 211 |
$headers['Authorization'] = 'AWS '. $settings['awsID'] .':'. $signature; |
if (!is_null($body)) { |
| 212 |
|
$headers['Content-MD5'] = hex2b64(md5($body)); |
| 213 |
|
} |
| 214 |
|
|
| 215 |
// Build S3 authorization hash. |
// Build S3 authorization hash. |
| 216 |
$auth_string = $method ."\n\n". $headers['Content-type'] ."\n" . $headers['Date'] ."\n"; |
$auth_string = $method ."\n"; |
| 217 |
|
// Apparently we need a trailing \n whether we have a body or not... |
| 218 |
|
if (isset($headers['Content-MD5'])) { |
| 219 |
|
$auth_string .= $headers['Content-MD5']; |
| 220 |
|
} |
| 221 |
|
$auth_string .= "\n" . $headers['Content-Type'] ."\n" . $headers['Date'] ."\n"; |
| 222 |
|
// Apparently we DONT need a trailing \n here if its not present. |
| 223 |
if (count($amzheaders)) { |
if (count($amzheaders)) { |
| 224 |
$auth_string .= implode("\n",$amzheaders) ."\n"; |
$auth_string .= implode("\n",$amzheaders) ."\n"; |
| 225 |
} |
} |