Zig
Zig
S3 Download String Object
See more Amazon S3 Examples
Demonstrates how to download a text file (i.e. object) from the Amazon S3 service directly into an in-memory string variable.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 assumes the Chilkat 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");
// This bucket is in the us-east-1 region.
http.setAwsRegion("us-east-1");
const bucket_name = "chilkat-test-bucket";
const object_name = "fruit.xml";
const charset = "utf-8";
const file_contents = http.s3DownloadString(alloc, bucket_name, object_name, charset) catch "";
if (!http.getLastMethodSuccess()) {
// Failed
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
} else {
// Success
std.debug.print("{s}\n", .{file_contents});
}
}