** openwrt下 luci.http.setfilehandler 上传文件失败**
function importconfig()
local http = require "luci.http"
local archive_tmp = "/tmp/file.data"
local Status = false
local errorinfo
local fp
local msg
http.setfilehandler(
function(meta, chunk, eof)
if not fp and meta and meta.name == "file_import" then
fp = io.open(archive_tmp, "w")
if nil == fp then
msg = "The storage space is insufficient."
return
end
end
if fp and chunk then
if 0 == #chunk then
msg = "Failed to upload the file."
return
end
local ret = fp:write(chunk)
if not ret then
msg = "The storage space is insufficient."
return
end
end
if fp and eof then
fp:close()
end
end
)
local jsonData = {
status = Status,
error = errorinfo
}
luci.http.prepare_content("application/json")
luci.http.write_json(jsonData)
end
运行结果及报错内容
一直会执行 0 == #chunk,提示上传文件失败
抓包看文件已经上传