Created
August 26, 2020 08:07
-
-
Save tonytonyjan/d2a612f2b3f37837fc4d5c1409ac0b1e to your computer and use it in GitHub Desktop.
wrk file upload example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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