Lua
Lua
Upload File with User-Defined Metadata
See more Amazon S3 Examples
Demonstrates how to upload a file with user-defined metadata to the Amazon S3 service.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Insert your AWS keys here:
http.aws_access_key = "AWS_ACCESS_KEY"
http.aws_secret_key = "AWS_SECRET_KEY"
local bucketName = "chilkat.ocean"
local objectName = "seahorse.jpg"
local localFilePath = "qa_data/jpg/seahorse.jpg"
local contentType = "image/jpg"
-- User-defined metadata are name/value pairs, and are added to the HTTP request header.
-- Header names must begin with "x-amz-meta-" to distinguish them from other HTTP headers.
-- Note that Amazon S3 stores user-defined metadata keys in lowercase.
-- For example, to add genus=Hippocampus, we do this:
http:set_request_header("x-amz-meta-genus", "Hippocampus")
-- Add a few more user-metadata key pairs.
http:set_request_header("x-amz-meta-species", "big-belly seahorse")
http:set_request_header("x-amz-meta-habitat", "shallow tropical and temperate waters")
local success = http:s3_upload_file(localFilePath, contentType, bucketName, objectName)
if not success then
print(http.last_error_text)
else
print("File uploaded.")
end