I'm trying to download files from my server with socket.http; I had it working before, but lost the code.
I'm now trying to recreate the code I made before, but I'm running into the problem that the downloaded file gets corrupted.
In the case of .ogg files, I couldn't even play them. In the case of .wav files, you can faintly hear the sound, but it's mainly noise.
This is my code:
Code: Select all
local http = require("socket.http")
local ltn12 = require("ltn12")
local url = "http://tjakka5.sorunome.de/Extern%20Files/Projects/Data/Soundboard/Tjakka5/Data/Sounds/How%20could%20this%20happen.wav"
local path = "How could this happen.wav"
local down = 0
function counter(chunk)
if chunk and chunk ~= "" then
down = down + #chunk
end
return chunk
end
http.request({
method = "GET",
url = url,
sink = ltn12.sink.chain(
counter,
ltn12.sink.file(io.open(path, "w"))
)
})
(The counter function is because I want to track progress as it's downloading.)