मैं एस 3 बाल्टी से सामग्री को पकड़ने के लिए एस 3 पर फ़ाइलों को संग्रहीत करने वाले क्लाइंट के लिए एक ZipArchive में शामिल करने के तरीके को समझने की कोशिश कर रहा हूं, अब उन्हें उन रिपोर्टों को बनाने की आवश्यकता है जो उन फ़ाइलों को पकड़ते हैं जिन्हें S3 तक धक्का दिया गया था ग्राहकों।PHP एसडीके 2 के माध्यम से एस 3 से ऑब्जेक्ट की सामग्री को पकड़ना?
require 'AWSSDKforPHP/aws.phar';
use Aws\S3\S3Client;
use Aws\Common\Enum\Region;
$config = array(
'key' => 'the-aws-key',
'secret' => 'the-aws-secret',
'region' => Region::US_EAST_1
);
$aws_s3 = S3Client::factory($config);
$app_config['s3']['bucket'] = 'the-aws-bucket';
$app_config['s3']['prefix'] = '';
$attach_name = 'hosted-test-file.jpg';
try {
$result = $aws_s3->getObject(
array(
'Bucket' => $app_config['s3']['bucket'],
'Key' => $app_config['s3']['prefix'].$attach_name
)
);
var_dump($result);
$body = $result->get('Body');
var_dump($body);
$handle = fopen('php://temp', 'r');
$content = stream_get_contents($handle);
echo "String length: ".strlen($content);
} catch(Aws\S3\Exception\S3Exception $e) {
echo "Request failed.<br />";
}
हालांकि, सभी यह रिटर्न एक Guzzle\Http\EntityBody
वस्तु, नहीं यकीन है कि कैसे वास्तविक सामग्री हड़पने के लिए तो मैं यह ज़िप में धक्का कर सकते हैं: मैं PHP एसडीके 2 एपीआई (नाशपाती के साथ स्थापित) के साथ निम्नलिखित की कोशिश की है फ़ाइल।
object(Guzzle\Service\Resource\Model)[126]
protected 'structure' => object(Guzzle\Service\Description\Parameter)[109]
protected 'name' => null
protected 'description' => null
protected 'type' => string 'object' (length = 6)
protected 'required' => boolean false
protected 'enum' => null
protected 'additionalProperties' => boolean true
protected 'items' => null
protected 'parent' => null
protected 'ref' => null
protected 'format' => null
protected 'data' => array (size = 11)
'Body' => object(Guzzle\Http\EntityBody)[97]
protected 'contentEncoding' => boolean false
protected 'rewindFunction' => null
protected 'stream' => resource(292, stream)
protected 'size' => int 3078337
protected 'cache' => array (size = 9)
...
'DeleteMarker' => string '' (length = 0)
'Expiration' => string '' (length = 0)
'WebsiteRedirectLocation' => string '' (length = 0)
'LastModified' => string 'Fri, 30 Nov 2012 21:07:30 GMT' (length = 29)
'ContentType' => string 'binary/octet-stream' (length = 19)
'ContentLength' => string '3078337' (length = 7)
'ETag' => string '"the-etag-of-the-file"' (length = 34)
'ServerSideEncryption' => string '' (length = 0)
'VersionId' => string '' (length = 0)
'RequestId' => string 'request-id' (length = 16)
object(Guzzle\Http\EntityBody)[96]
protected 'contentEncoding' => boolean false
protected 'rewindFunction' => null
protected 'stream' => resource(292, stream)
protected 'size' => int 3078337
protected 'cache' => array (size = 9)
'wrapper_type' => string 'php' (length = 3)
'stream_type' => string 'temp' (length = 4)
'mode' => string 'w+b' (length = 3)
'unread_bytes' => int 0
'seekable' => boolean true
'uri' => string 'php://temp' (length = 10)
'is_local' => boolean true
'is_readable' => boolean true
'is_writable' => boolean true
// Echo of strlen()
String length: 0
कोई भी जानकारी उच्च सराहना की होगी, धन्यवाद!
समाधान
यह मुझे थोड़ी देर के लिए यह पता लगाने की है, लेकिन मैं आदेश फ़ाइल की सामग्री को प्राप्त करने के लिए, एक सार है कि मुझे सही दिशा में बताया ढूँढने में सक्षम था आप निम्नलिखित करने की ज़रूरत है :
require 'AWSSDKforPHP/aws.phar';
use Aws\S3\S3Client;
use Aws\Common\Enum\Region;
$config = array(
'key' => 'the-aws-key',
'secret' => 'the-aws-secret',
'region' => Region::US_EAST_1
);
$aws_s3 = S3Client::factory($config);
$app_config['s3']['bucket'] = 'the-aws-bucket';
$app_config['s3']['prefix'] = '';
$attach_name = 'hosted-test-file.jpg';
try {
$result = $aws_s3->getObject(
array(
'Bucket' => $app_config['s3']['bucket'],
'Key' => $app_config['s3']['prefix'].$attach_name
)
);
$body = $result->get('Body');
$body->rewind();
$content = $body->read($result['ContentLength']);
} catch(Aws\S3\Exception\S3Exception $e) {
echo "Request failed.<br />";
}
तुम सच में एक EntityBody वस्तु से अंतर्निहित पीएचपी धारा संसाधन हड़पने के लिए की जरूरत है, आप कर सकते हैं सब 'getStream()' विधि। EntityBody ऑब्जेक्ट के एपीआई दस्तावेज़ों के लिए http://guzzlephp.org/api/class-Guzzle.Http.EntityBody.html देखें। –