Beispiel #1
0
 /**
  * Start a multipart upload of an object
  *
  * @param   Input   $input           Input data
  * @param   string  $bucket          Bucket name
  * @param   string  $uri             Object URI
  * @param   string  $acl             ACL constant
  * @param   array   $requestHeaders  Array of request headers
  *
  * @return  string  The upload session ID (UploadId)
  */
 public function startMultipart(Input $input, $bucket, $uri, $acl = Acl::ACL_PRIVATE, $requestHeaders = array())
 {
     $request = new Request('POST', $bucket, $uri, $this->configuration);
     $request->setParameter('uploads', '');
     // Custom request headers (Content-Type, Content-Disposition, Content-Encoding)
     if (is_array($requestHeaders)) {
         foreach ($requestHeaders as $h => $v) {
             if (strtolower(substr($h, 0, 6)) == 'x-amz-') {
                 $request->setAmzHeader(strtolower($h), $v);
             } else {
                 $request->setHeader($h, $v);
             }
         }
     }
     $request->setAmzHeader('x-amz-acl', $acl);
     if (isset($requestHeaders['Content-Type'])) {
         $input->setType($requestHeaders['Content-Type']);
     }
     $request->setHeader('Content-Type', $input->getType());
     $response = $request->getResponse();
     if (!$response->error->isError() && $response->code !== 200) {
         $response->error = new Error($response->code, "Unexpected HTTP status {$response->code}");
     }
     if ($response->error->isError()) {
         throw new CannotPutFile(sprintf(__METHOD__ . "(): [%s] %s\n\nDebug info:\n%s", $response->error->getCode(), $response->error->getMessage(), print_r($response->body, true)));
     }
     return (string) $response->body->UploadId;
 }