Zig
Zig
S3 Delete Bucket Object
See more Amazon S3 (new) Examples
Deletes an object in a bucket.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const rest = try chilkat.Rest.init();
defer rest.deinit();
// Connect to the Amazon AWS REST server.
const b_tls = true;
const port = 443;
const b_auto_reconnect = true;
try rest.connect("s3.amazonaws.com", port, b_tls, b_auto_reconnect);
// ----------------------------------------------------------------------------
// Important: For buckets created in regions outside us-east-1,
// there are three important changes that need to be made.
// See Working with S3 Buckets in Non-us-east-1 Regions for the details.
// ----------------------------------------------------------------------------
// Provide AWS credentials for the REST call.
const auth_aws = try chilkat.AuthAws.init();
defer auth_aws.deinit();
auth_aws.setAccessKey("AWS_ACCESS_KEY");
auth_aws.setSecretKey("AWS_SECRET_KEY");
auth_aws.setServiceName("s3");
try rest.setAuthAws(auth_aws);
// Set the bucket name via the HOST header.
// In this case, the bucket name is "chilkat100".
rest.setHost("chilkat100.s3.amazonaws.com");
// This example deletes the object named "Abc.ics"
const sb_response = try chilkat.StringBuilder.init();
defer sb_response.deinit();
rest.fullRequestNoBodySb("DELETE", "/Abc.ics", sb_response) catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
// If successfully deleted, the response status code is 204 and the response body text will be empty.
const status_code = rest.getResponseStatusCode();
std.debug.print("Response status code = {d}\n", .{status_code});
std.debug.print("Response text = \n", .{});
std.debug.print("{s}\n", .{try sb_response.getAsString(alloc)});
}