2013-08-30 2 views
0

PHP 5.3을 사용하여 AWS 다중 파트 업로드에 대한 도움말이 필요합니다. 1. WAMP 서버. 2. PHP 5.3 3. OS : Windows 8 Big 파일을 My Amazon S3 버킷에 업로드하려고합니다.AWS Multipart 업로드 SDK가 작동하지 않습니다.

여러 가지 방법으로 시도했습니다. 나는 코드 절차를 따랐다. http://docs.aws.amazon.com/AmazonS3/latest/dev/LLuploadFilePHP.html

나는 PHP 코드를 썼지 만, 나는 어떤 실수를했는지 모른다.

내 코드 :

<?php 
     require_once './sdk/sdk.class.php'; 

    use \AmazonS3; 

    $ufile = $_FILES['ufile']; 
    $filepath = $ufile['tmp_name']; 
    $bucket = '**My_bkt**'; 
    var_dump($ufile); 
    print $keyname = \date("Y") . "/" . \date("F") . "/" . \date("d") . "/" . $ufile['name'] . "<BR />"; 


    $api_key = "***my_api_key***"; 
    $secret_key = "***my_secret_key***"; 


    // Define a megabyte. 
    define('MB', 1048576); 

    // Instantiate the class 
    //$s3 = new AmazonS3(); 
    $s3 = new AmazonS3(array(
     'key' => $api_key, 
     'secret' => $secret_key, 
      )); 

    // 1. Initiate a new multipart upload. 
    /* @var $response type */ 
    $response = $s3->initiate_multipart_upload($bucket, $keyname); 

    // Get the Upload ID. 
    $upload_id = (string) $response->body->UploadId; 

    // 2. Upload parts. 
    // Get part list for a given input file and given part size. 
    // Returns an associative array. 
    $parts = $s3->get_multipart_counts(filesize($filepath), 3 * MB); 

    foreach ($parts as $i => $part) { 
     // Upload part and save response in an array. 
     $responses[] = $s3->upload_part($bucket, $keyname, $upload_id, array(
      'fileUpload' => $filepath, 
      'partNumber' => ($i + 1), 
      'seekTo' => (integer) $part['seekTo'], 
      'length' => (integer) $part['length'], 
       ) 
     ); 
    } 

    // 3. Complete multipart upload. We need all part numbers and ETag values. 
    $parts = $s3->list_parts($bucket, $keyname, $upload_id); 

    $response = $s3->complete_multipart_upload($bucket, $keyname, $upload_id, $parts); 

    var_dump($response); 

제발 도와주세요.

+1

오류를 찾으셨습니까? –

답변

0

내가 내 SDK 업데이트하고 우는 소리처럼 내 코드를 변경 한

////////////////// AWS 코드 시작 ///////// /////////// ///////////////////////// step 1 ///////// ////////////////////

$ufile = $_FILES['Filedata']; 
$filename = $ufile['tmp_name']; 
$filesize = $ufile['size']; 

/*  * ************ Calculating Number of Parts ******************* */ 
$number_of_parts = 0; 
$r = $filesize % PART; // Remainder 
$q = floor($filesize/PART); // Quotient 
if ($r != 0) { 
    $number_of_parts = $q + 1; 
} else { 
    $number_of_parts = $q; 
} 
$bucket = 'isource123'; 
$keyname = date("Y") . "/" . date("F") . "/" . date("d") . "/" . $ufile['name']; 

/////////////////////// ////// 2 단계 ///////////////////// // 구성 파일을 사용하여 서비스 빌더 만들기

$aws = Aws::factory('./aws/Aws/Common/Resources/aws-config.php'); 

// Get the client from the builder by namespace 
    $client = $aws->get('S3'); 
$uploader = \Aws\S3\Model\MultipartUpload\UploadBuilder::newInstance() 
     ->setClient($client) 
     ->setSource($filename) 
     ->setBucket($bucket) 
     ->setKey($keyname) 
     ->setOption('Metadata', array('Foo' => 'Bar')) 
     ->setOption('CacheControl', 'max-age=3600') 
     ->setConcurrency($number_of_parts) 
     ->build(); 

try { 
    $uploader->upload(); 
    echo "Upload complete.\n"; 
} catch (MultipartUploadException $e) { 
    $uploader->abort(); 
    echo "Upload failed.\n"; 
} 
1

이전 SDK 1을 사용하고 있다는 것을 알고 있습니다. 따라서 내 답변은 게시 한 항목에 직접 적용되지 않습니다. 즉, SDK 1.x는 더 이상 업데이트되지 않으며 SDK 2.x는 새로운 작업 (PHP 팀 용 AWS SDK 별)을 사용해야한다는 것입니다.

SDK 2를 사용하도록 프로젝트를 업데이트 한 경우 S3Client::upload()을 살펴보십시오. 크게은 여기서 수행하려는 작업을 간소화해야합니다.

+0

예, 업데이트되어 잘 작동합니다. –

0

내 SDK를 버전 2로 업데이트했는데 정상적으로 작동합니다.