delete_object ( $bucket, $filename, $opt )

Deletes an Amazon S3 object from the specified bucket.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

$filename

string

Required

The file name for the object.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • versionId - string - Optional - The version of the object to delete. Version IDs are returned in the x-amz-version-id header of any previous object-related request.
  • MFASerial - string - Optional - The serial number on the back of the Gemalto device. MFASerial and MFAToken must both be set for MFA to work.
  • MFAToken - string - Optional - The current token displayed on the Gemalto device. MFASerial and MFAToken must both be set for MFA to work.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Delete an object.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

$response = $s3->delete_object($bucket, 'prefix with spaces/åéîøü/åéîøü/åéîøü with spaces.txt');

// Success?
var_dump($response->isOK());
Result:
bool(true)

Delete a specific version of an object.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

// Delete a specific version
$response = $s3->delete_object($bucket, 'test1.txt', array(
	'versionId' => '0NNAq8PwvXvg8EfAYG9sSmwKTZeixZgZNE6PbodG8td0DJ3gVOmjI2Gh/oFnb0Ie='
));

// Success?
var_dump($response->isOK());
var_dump(strpos((string) $response->header['_info']['url'], 'versionId=' . $version_id) !== false);
Result:
bool(true)
bool(true)

Delete a specific version of an object from an MFA-protected bucket.

// Instantiate the class
$s3 = new AmazonS3();

$response = $s3->delete_object('my-bucket', 'test1.txt', array(
	'versionId' => '0NNAq8PwvXvg8EfAYG9sSmwKTZeixZgZNE6PbodG8td0DJ3gVOmjI2Gh/oFnb0Ie=',
	'MFASerial' => CFCredentials::get()->mfa_serial, // Custom property in the config file.
	'MFAToken' => '12345678'
));

// Success?
var_dump($response->isOK());
var_dump(strpos((string) $response->header['_info']['url'], 'versionId=' . $version_id) !== false);
Result:
bool(true)
bool(true)

Related Methods

See Also

Source

Method defined in services/s3.class.php | Toggle source view (20 lines) | View on GitHub

public function delete_object($bucket, $filename, $opt = null)
{
    // Add this to our request
    if (!$opt) $opt = array();
    $opt['verb'] = 'DELETE';
    $opt['resource'] = $filename;

    // Enable MFA delete?
    // @codeCoverageIgnoreStart
    if (isset($opt['MFASerial']) && isset($opt['MFAToken']))
    {
        $opt['headers'] = array(
            'x-amz-mfa' => ($opt['MFASerial'] . ' ' . $opt['MFAToken'])
        );
    }
    // @codeCoverageIgnoreEnd

    // Authenticate to S3
    return $this->authenticate($bucket, $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback