Zig
Zig
S3 Upload File
See more Amazon S3 Examples
Demonstrates how to upload a file to the Amazon S3 service.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// 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 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";
// The Content-Type has the form type/subtype, such as application/pdf, application/json, image/jpeg, etc.
// See Explaining Content-Types
const content_type = "image/jpeg";
success = if (http.s3UploadFile(local_file_path, content_type, bucket_name, object_name)) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
} else {
std.debug.print("File uploaded.\n", .{});
}
}