Google Cloud Storage

Objects: delete

Deletes data blobs and associated metadata. Deletions are permanent if versioning is not enabled for the bucket, or if the generation parameter is used. Try it now or see an example.

The invoking user must have either FULL_CONTROL of the object or WRITE permission on the bucket.

Request

HTTP request

DELETE https://www.googleapis.com/storage/v1beta2/b/bucket/o/object

Parameters

Parameter name Value Description
Path parameters
bucket string Name of the bucket in which the object resides.
object string Name of the object.
Optional query parameters
generation unsigned long If present, permanently deletes a specific revision of this object (as opposed to the latest version, the default).
ifGenerationMatch unsigned long Makes the operation conditional on whether the object's current generation matches the given value.
ifGenerationNotMatch unsigned long Makes the operation conditional on whether the object's current generation does not match the given value.
ifMetagenerationMatch unsigned long Makes the operation conditional on whether the object's current metageneration matches the given value.
ifMetagenerationNotMatch unsigned long Makes the operation conditional on whether the object's current metageneration does not match the given value.

Request body

Do not supply a request body with this method.

Response

If successful, this method returns an empty response body.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library

storage.objects().delete("mybucket", "myobject").execute();

Python

Uses the Python client library

client.objects().delete(
        bucket=bucket_name,
        object=object_name).execute()

Ruby

Uses the Ruby client library

# Delete object from bucket
object_delete_result = client.execute(
  api_method: storage.objects.delete,
  parameters: {bucket: BUCKET, object: OBJECT}
)
if object_delete_result.response.status == 204
  puts "Successfully deleted #{OBJECT}.\n"
else
  puts "Failed to delete #{OBJECT}.\n"
end

Go

Uses the Go client library

// Delete an object from a bucket.
bucketName := "BUCKET_NAME"
objectName := "OBJECT_NAME"
if err = service.Objects.Delete(bucketName, objectName).Do(); err == nil {
	fmt.Printf("Successfully deleted %s/%s.\n\n", bucketName, objectName)
} else {
	fmt.Printf("Objects.Delete errors: %v\n\n", err)
}

Try it!

Use the APIs Explorer below to call this method on live data and see the response. Alternatively, try the standalone Explorer.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.