Lua
Lua
HTTPS Upload File to Web Server
See more HTTP Examples
Uploads a file to a web server using HTTPS.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
-- The ContentType, HttpVerb, and Path properties should
-- always be explicitly set.
local req = chilkat.HttpRequest.new()
req.http_verb = "POST"
req.path = "/receiveMyUpload.aspx"
req.content_type = "multipart/form-data"
req:add_string_for_upload("fileA", "fileA.txt", "This is the contents of file A", "utf-8")
local success = req:add_file_for_upload("starfish.jpg", "qa_data/jpg/starfish.jpg")
if not success then
print(req.last_error_text)
return
end
local http = chilkat.Http.new()
-- ----------------------------------------------------------------------------
-- IMPORTANT:
-- HTTP uploads require a counterpart implementation on the server, written in any desired language
-- such as C#, Classic ASP, PHP, etc., which consumes the upload being sent.
-- See: ASP.NET Receive Upload
-- ----------------------------------------------------------------------------
-- Do the upload.
local useSslTls = true
local resp = chilkat.HttpResponse.new()
success = http:http_sreq("www.example.com", 443, useSslTls, req, resp)
if not success then
print(http.last_error_text)
return
end
print("response status code = " .. resp.status_code)
print("response body:")
print(resp.body_str)