Esempio n. 1
0
 /**
  * Upload request
  *
  * @param string       $body
  * @param string|array $key
  * @param array        $policy
  * @return bool|Result
  */
 public function uploadRequest($body, $key, $policy = null)
 {
     $options = (is_string($key) ? array('key' => $key) : array()) + array('filename' => null);
     $policy = (array) $policy + array('scope' => $this->options['bucket'], 'deadline' => time() + 3600, 'callbackUrl' => null, 'callbackBody' => null, 'returnUrl' => null, 'returnBody' => null, 'asyncOps' => null, 'endUser' => null);
     foreach ($policy as $k => $v) {
         if ($v === null) {
             unset($policy[$k]);
         }
     }
     $token = $this->mac->signWithData(json_encode($policy));
     $request = Request::create(array('url' => $this->options['upload_url'], 'method' => 'POST', 'headers' => array('content-type' => 'multipart/form-data'), 'form' => array('token' => $token, 'key' => $options['key'])))->file($body, basename($options['filename'] ? $options['filename'] : $options['key']));
     $result = new Result($request->send(), $request);
     if ($result->ok()) {
         $result->data['url'] = $this->options['base_url'] . '/' . $result->data['key'];
     }
     return $result;
 }
Esempio n. 2
0
 public function testSignWithData()
 {
     $this->assertEquals('test:b25MJSh2VIQPTdMvs7POrsTIvEE=:dGVzdA==', $this->mac->signWithData('test'));
 }