Пример #1
0
 /**
  * Finalizes the multi-part upload. The $input object should contain two keys, etags an array of ETags of the
  * uploaded parts and UploadID the multipart upload ID.
  *
  * @param   Input   $input   The array of input elements
  * @param   string  $bucket  The bucket where the object is being stored
  * @param   string  $uri     The key (path) to the object
  *
  * @return  void
  */
 public function finalizeMultipart(Input $input, $bucket, $uri)
 {
     $etags = $input->getEtags();
     $UploadID = $input->getUploadID();
     if (empty($etags)) {
         throw new CannotPutFile(__METHOD__ . '(): No ETags array specified');
     }
     if (empty($UploadID)) {
         throw new CannotPutFile(__METHOD__ . '(): No UploadID specified');
     }
     // Create the message
     $message = "<CompleteMultipartUpload>\n";
     $part = 0;
     foreach ($etags as $etag) {
         $part++;
         $message .= "\t<Part>\n\t\t<PartNumber>{$part}</PartNumber>\n\t\t<ETag>\"{$etag}\"</ETag>\n\t</Part>\n";
     }
     $message .= "</CompleteMultipartUpload>";
     // Get a request query
     $reqInput = Input::createFromData($message);
     $request = new Request('POST', $bucket, $uri, $this->configuration);
     $request->setParameter('uploadId', $UploadID);
     $request->setInput($reqInput);
     // Do post
     $request->setHeader('Content-Type', 'application/xml');
     // Even though the Amazon API doc doesn't mention it, it's required... :(
     $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()) {
         if ($response->error->getCode() == 'RequestTimeout') {
             return;
         }
         throw new CannotPutFile(sprintf(__METHOD__ . "(): [%s] %s\n\nDebug info:\n%s", $response->error->getCode(), $response->error->getMessage(), print_r($response->body, true)));
     }
 }