Amazon S3多部件上载返回NULL

时间:2017-06-11 20:40:00

标签: php amazon-web-services amazon-s3

我正在尝试上传8GB文件,但它不断返回null。我也没有收到错误消息没有抛出异常。 null显示在va_dump中,正常s3 - > putObject适用于5GB以下的文件。我的代码如下:

$s3 = S3Client::factory(array(
            'credentials' => array(
                'secret' => 'xxx',
                'key' => 'xxxxx'
            ),
            'region' => 'us-west-2',
            'version' => '2006-03-01'
        ));;

        try {

            if(filesize($body) < 5000000000) {

                $result = $s3->putObject(array(
                    'Bucket'       => $bucket,
                    'Key'          => $obect,
                    'SourceFile'   => $body,
                    'ContentType'  => $content_type,
                    'ACL'          => $acl,
                ));

                return $result['ObjectURL'];

            } else {

                echo 'Starting Uploads';

                $source = fopen($body, 'rb');

                $uploader = new MultipartUploader($s3, $source
                , [
                    'bucket' => $bucket,
                    'key'    => $obect,
                    'acl'    => $acl,
                    'concurrency' => 5,
                    'part_size' => (100 * 1024 * 1024),
                    'before_initiate' => function(\Aws\Command $command) use ($content_type) {
                        $command['ContentType'] = $content_type;  //  video/mp4
                    }
                ]);

                echo 'Into Upload';

                $result = $uploader->upload();

                echo 'Complete Upload';

                var_dump($result);

                return (isset($result['Location'])) ? $result['Location'] : false;

            }
        } catch (MultipartUploadException $e) {
            error_log($e -> getMessage() . ' ' . $e -> getTraceAsString());
             $uploader = new \Aws\S3\MultipartUploader($s3, $body, [
                'state' => $e->getState(),
             ]);

            return false;
        } catch (Aws\Exception\S3Exception $e) {
            error_log($e -> getMessage() . ' ' . $e -> getTraceAsString());
            return false;
        } catch (Exception $e) {
            error_log($e -> getMessage() . ' ' . $e -> getTraceAsString());
            return false;
        }

        return false;

0 个答案:

没有答案