Sample code for 30+ languages & platforms
Zig

S3 Delete File

See more Amazon S3 Examples

Demonstrates how to delete a remote file (object) on the Amazon S3 service.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example assumes the Chilkat HTTP API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Insert your access key here:
    http.setAwsAccessKey("AWS_ACCESS_KEY");

    // Insert your secret key here:
    http.setAwsSecretKey("AWS_SECRET_KEY");

    const bucket_name = "chilkattest";
    const object_name = "starfish.jpg";

    http.setKeepResponseBody(true);

    http.s3DeleteObject(bucket_name, object_name) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    if (http.getLastStatus() != 204) {
        std.debug.print("Status code = {d}\n", .{http.getLastStatus()});
        std.debug.print("{s}\n", .{try http.getLastResponseBody(alloc)});
        std.debug.print("Failed.\n", .{});
        return;
    }

    // 204 is the success response status.
    // When successful, the response body will be empty.
    std.debug.print("Status code = {d}\n", .{http.getLastStatus()});
    std.debug.print("Success. Object deleted.\n", .{});
}