Classic ASP AWS S3: Delete File from an S3 Bucket

Back to Index

Demonstrates how to delete a file from an S3 bucket. This example deletes the file /chilkat.ocean/starfishCopy.jpg. A response status code equal to 204 is returned for success (with an empty response body).

Documentation: https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectDELETE.html

CURL Command

curl -X DELETE https://chilkat.ocean.s3.us-west-2.amazonaws.com/starfishCopy.jpg

Classic ASP Example

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
set rest = Server.CreateObject("Chilkat_9_5_0.Rest")

set authAws = Server.CreateObject("Chilkat_9_5_0.AuthAws")
authAws.AccessKey = "AWS_ACCESS_KEY"
authAws.SecretKey = "AWS_SECRET_KEY"
authAws.Region = "us-west-2"
authAws.ServiceName = "s3"
success = rest.SetAuthAws(authAws)

'  URL: https://chilkat.ocean.s3.us-west-2.amazonaws.com/starfishCopy.jpg
bTls = 1
port = 443
bAutoReconnect = 1
success = rest.Connect("chilkat.ocean.s3.us-west-2.amazonaws.com",port,bTls,bAutoReconnect)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "ConnectFailReason: " & rest.ConnectFailReason) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
    Response.End
End If

set sbResponseBody = Server.CreateObject("Chilkat_9_5_0.StringBuilder")
success = rest.FullRequestNoBodySb("DELETE","/starfishCopy.jpg",sbResponseBody)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
    Response.End
End If

respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Response Status Code = " & respStatusCode) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "Response Header:") & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( rest.ResponseHeader) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "Response Body:") & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( sbResponseBody.GetAsString()) & "</pre>"
    Response.End
End If


%>
</body>
</html>