local https = require 'ssl.https'
local ltn12 = require 'ltn12'
local lfs = require 'lfs'
https.TIMEOUT = 5
function upload_file(url, filename)
local fileHandle = io.open(filename, 'rb')
if fileHandle then
local fileContent = fileHandle:read('*a')
fileHandle:close()
local boundary = 'abcd'
local header_b = 'Content-Disposition: form-data; name="file"; filename="' .. filename .. '"\r\nContent-Type: text/plain\r\n'
local fileContent = '--' ..boundary .. '\r\n' ..header_b ..'\r\n'.. fileContent .. '\r\n--' .. boundary ..'--\r\n'
local response_body = { }
local _, code = https.request {
url = url ,
method = 'POST',
headers = {
['Content-Length'] = fileContent:len(),
['Content-Type'] = 'multipart/form-data; boundary='..boundary
},
source = ltn12.source.string(fileContent),
sink = ltn12.sink.table(response_body),
}
return code, table.concat(response_body)
else
return false, 'File Not Found'
end
end