/[drupal]/contributions/modules/fileapi/drivers/s3.driver
ViewVC logotype

Diff of /contributions/modules/fileapi/drivers/s3.driver

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3.4.1, Thu Jan 4 09:24:40 2007 UTC revision 1.3.4.2, Thu Jan 4 11:07:59 2007 UTC
# Line 2  Line 2 
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    
# Line 84  function fileapi_driver_s3_settings_form Line 86  function fileapi_driver_s3_settings_form
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  }  }
# Line 164  function fileapi_driver_s3_touch($settin Line 166  function fileapi_driver_s3_touch($settin
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    
# Line 177  function fileapi_driver_s3_touch($settin Line 180  function fileapi_driver_s3_touch($settin
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  /**  /**
# Line 189  function fileapi_driver_s3_readdir($sett Line 192  function fileapi_driver_s3_readdir($sett
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    
# Line 205  function s3_request($method, $resource, Line 208  function s3_request($method, $resource,
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    }    }

Legend:
Removed from v.1.3.4.1  
changed lines
  Added in v.1.3.4.2

  ViewVC Help
Powered by ViewVC 1.1.2