Skip to content

Instantly share code, notes, and snippets.

@tonytonyjan
Created August 26, 2020 08:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tonytonyjan/d2a612f2b3f37837fc4d5c1409ac0b1e to your computer and use it in GitHub Desktop.
Save tonytonyjan/d2a612f2b3f37837fc4d5c1409ac0b1e to your computer and use it in GitHub Desktop.
wrk file upload example
function read_file(path)
local file, errorMessage = io.open(path, "rb")
if not file then
error("Could not read the file:" .. errorMessage .. "\n")
end
local content = file:read "*all"
file:close()
return content
end
local Boundary = "----WebKitFormBoundaryePkpFF7tjBAqx29L"
local BodyBoundary = "--" .. Boundary
local LastBoundary = "--" .. Boundary .. "--"
local CRLF = "\r\n"
local FileBody = read_file("test/fixtures/files/test.jpg")
local Filename = "test.jpg"
local ContentDisposition = 'Content-Disposition: form-data; name="files[]"; filename="' .. Filename .. '"'
local ContentType = 'Content-Type: image/jpeg'
wrk.method = "POST"
wrk.headers["Content-Type"] = "multipart/form-data; boundary=" .. Boundary
wrk.body = BodyBoundary .. CRLF .. ContentDisposition .. CRLF .. ContentType .. CRLF .. CRLF .. FileBody .. CRLF .. LastBoundary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment