The object is the basic storage unit in S3. Object stores unstructured data, which can be any size up to 4 gigabytes. There's no limit on how many objects can be stored on the system.
The object are contained in buckets. Object is identified by name, which can be any
utf-8 string. It is common to use hierarchical names (such as
Pictures/Myself/CodingInPHP.jpg) to organise object names. Object name is
prefixed with bucket name when using object functions, so for object "mydata" in bucket
"my-own-bucket" the name would be my-own-bucket/mydata.
Objects can be replaced (by rewriting new data with the same key) or deleted, but not modified, appended, etc. Object is always stored whole.
By default, all objects are private and can be accessed only by their owner. However, it
is possible to specify object with public access, in which case it will be available
through the URL:
http://s3.amazonaws.com/[bucket-name]/[object-name].
-
putObject($object, $data, $meta)created an object with name$object(should contain the bucket name as prefix!) having$dataas its content.Optional
$metaparameter is the array of metadata, which currently supports the following parameters as keys:S3_CONTENT_TYPE_HEADERMIME content type of the data. If not specified, the type will be guessed according to the file extension of the object name.
S3_ACL_HEADER-
The access to the item. Following access constants can be used:
S3_ACL_PRIVATEOnly the owner has access to the item.
S3_ACL_PUBLIC_READAnybody can read the object, but only owner can write. This is setting may be used to store publicly accessible content.
S3_ACL_PUBLIC_WRITEAnybody can read or write the object. This policy is rarely useful.
S3_ACL_AUTH_READOnly the owner has write access to the item, and other authenticated S3 users have read access. This is useful for sharing data between S3 accounts without exposing them to the public.
By default, all the items are private.
Example 754. Zend_Service_Amazon_S3 Public Object Example
<?php
require_once 'Zend/Service/Amazon/S3.php';
$s3 = new Zend_Service_Amazon_S3($my_aws_key, $my_aws_secret_key);
$s3->putObject("my-own-bucket/Pictures/Me.png", file_get_contents("me.png"),
array(Zend_Service_Amazon_S3::S3_ACL_HEADER =>
Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ));
// or:
$s3->putFile("me.png", "my-own-bucket/Pictures/Me.png",
array(Zend_Service_Amazon_S3::S3_ACL_HEADER =>
Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ));
echo "Go to http://s3.amazonaws.com/my-own-bucket/Pictures/Me.png to see me!\n";
getObject($object)retrieves object data from the storage by name.removeObject($object)removes the object from the storage.-
getInfo($object)retrieves the metadata information about the object. The function will return array with metadata information. Some of the useful keys are:typeThe MIME type of the item.
sizeThe size of the object data.
mtimeUNIX-type timestamp of the last modification for the object.
etagThe ETag of the data, which is the MD5 hash of the data, surrounded by quotes (").
The function will return
FALSEif the key does not correspond to any existing object. -
getObjectsByBucket($bucket)returns the list of the object keys, contained in the bucket.Example 755. Zend_Service_Amazon_S3 Object Listing Example
<?php
require_once 'Zend/Service/Amazon/S3.php';
$s3 = new Zend_Service_Amazon_S3($my_aws_key, $my_aws_secret_key);
$list = $s3->getObjectsByBucket("my-own-bucket");
foreach($list as $name) {
echo "I have $name key:\n";
$data = $s3->getObject("my-own-bucket/$name");
echo "with data: $data\n";
}
isObjectAvailable($object)checks if the object with given name exists.-
putFile($path, $object, $meta)puts the content of the file in$pathinto the object named$object.The optional
$metaargument is the same as forputObject. If the content type is omitted, it will be guessed basing on the source file name.




