Created
November 8, 2012 19:21
-
-
Save legumbre/4040928 to your computer and use it in GitHub Desktop.
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
http = require("socket.http") | |
ltn12 = require("ltn12") | |
function fsize (file) | |
local current = file:seek() -- get current position | |
local size = file:seek("end") -- get file size | |
file:seek("set", current) -- restore position | |
return size | |
end | |
pathToLocalFile="/tmp/server.py" | |
file = io.open(pathToLocalFile, "r") | |
sizeOfFile= fsize(file) | |
print(sizeOfFile) | |
file:close() | |
function upload () | |
local response_body={} | |
socket.http.request{ | |
url = "http://localhost:8000/upload", | |
method = "POST", | |
headers = { | |
["Content-Type"] = "multipart/form-data", | |
["Content-Length"] = sizeOfFile | |
}, | |
source = ltn12.source.file(io.open(pathToLocalFile)), | |
sink = ltn12.sink.table(response_body) | |
} | |
print(response_body[1]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment