lua接收图片并进行md5处理

需要luacurl(http://luacurl.luaforge.net/)和MD5两个库函数

curl = require("luacurl")
require("md5")
-- 下载图片
function get_img(url, c)
    local result = {}
    if c == nil then
        c = curl.new()
    end
    c:setopt(curl.OPT_URL, url)
    c:setopt(curl.OPT_WRITEDATA, result)
    c:setopt(curl.OPT_WRITEFUNCTION, function(tab, buffer)
        table.insert(tab, buffer)
        return #buffer
    end)
    local ok = c:perform()
    return ok, table.concat(result)
end
-- 图片url
downloadurl = "http://192.168.75.60:8090/FlexerDesigner/js/easyui134/themes/icons/filesave.png"
-- 函数调用
ok, fileByte = get_img(downloadurl)
-- 看是否执行成功
print(ok)
-- md5转码
md5 = md5.sumhexa(fileByte)
print(md5)
--[[
-- 保存图片
file = io.open("filesave.png", "w")
if(file) then
  file:write(fileByte);
  file:close();
end

]]
原文地址:https://www.cnblogs.com/tv151579/p/4476034.html