Deletes an object and its 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 authenticated user must have
WRITER
permissions on the
bucket
.
Request
HTTP request
DELETE https://www.googleapis.com/storage/v1/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
|
long
|
If present, permanently deletes a specific revision of this object (as opposed to the latest version, the default). |
ifGenerationMatch
|
long
|
Makes the operation conditional on whether the object's current generation matches the given value. |
ifGenerationNotMatch
|
long
|
Makes the operation conditional on whether the object's current generation does not match the given value. |
ifMetagenerationMatch
|
long
|
Makes the operation conditional on whether the object's current metageneration matches the given value. |
ifMetagenerationNotMatch
|
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 .