Zig
Zig
S3 Upload a File with Public Read Permissions
See more Amazon S3 Examples
Demonstrates how to upload a file to the Amazon S3 service with the x-amz-acl request header set to "public-read" to allow the file to be publicly downloadable.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 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 AWS keys here:
http.setAwsAccessKey("AWS_ACCESS_KEY");
http.setAwsSecretKey("AWS_SECRET_KEY");
const bucket_name = "chilkat.ocean";
const object_name = "seahorse.jpg";
const local_file_path = "qa_data/jpg/seahorse.jpg";
const content_type = "image/jpg";
// Add the x-amz-acl request header to make the file publicly readable.
http.setRequestHeader("x-amz-acl", "public-read");
http.s3UploadFile(local_file_path, content_type, bucket_name, object_name) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
if (http.getLastStatus() == 200) {
std.debug.print("File uploaded.\n", .{});
} else {
std.debug.print("Response status code: {d}\n", .{http.getLastStatus()});
std.debug.print("{s}\n", .{try http.getLastResponseBody(alloc)});
}
}