add md5 to http header

This commit is contained in:
XiaoLi
2023-07-23 21:38:56 +08:00
committed by XiaoLi
parent 632d53dbb9
commit 5be125956f
3 changed files with 29 additions and 2 deletions
+3
View File
@@ -411,6 +411,7 @@ local function _parse_upyun_option(option, extra, content)
if omd5 == "true" then if omd5 == "true" then
extra["Content-MD5"] = md5(content) extra["Content-MD5"] = md5(content)
--extra["Content-MD5"] = "cca354111e1980bec172a68718976c8"
end end
if type(secret) == "string" then if type(secret) == "string" then
@@ -420,6 +421,8 @@ local function _parse_upyun_option(option, extra, content)
if type(otype) == "string" then if type(otype) == "string" then
extra["Content-Type"] = otype extra["Content-Type"] = otype
end end
--print('options...', extra["Content-MD5"])
end end
local function _parse_upyun_headers(headers, regex) local function _parse_upyun_headers(headers, regex)
+13 -2
View File
@@ -1,5 +1,6 @@
-- 指定模块引用目录,否则无法加载同目录下的其他文件 -- 指定模块引用目录,否则无法加载同目录下的其他文件
--package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua'; --package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
--package.path = package.path .. ';/Users/liyong/Code/AlchemyStudio/resty_functions/scripts/?.lua';
package.path = package.path .. ';<SCRIPT_PATH>/?.lua'; package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
local upyun_upload = {} local upyun_upload = {}
@@ -11,6 +12,8 @@ function upyun_upload.upload(filepath, filename)
local upyun, err = Upyun:new({ local upyun, err = Upyun:new({
user = ngx.var.upyun_operator, user = ngx.var.upyun_operator,
passwd = ngx.var.upyun_password, passwd = ngx.var.upyun_password,
--user = "moicen",
--passwd = "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN",
localFilePath = filepath localFilePath = filepath
}) })
@@ -22,6 +25,8 @@ function upyun_upload.upload(filepath, filename)
local bucket = ngx.var.upyun_bucket local bucket = ngx.var.upyun_bucket
local directory = ngx.var.upyun_directory local directory = ngx.var.upyun_directory
--local bucket = "huiwing"
--local directory = "music-room"
if not filename then if not filename then
filename = strip_path.strip_path(filepath) filename = strip_path.strip_path(filepath)
end end
@@ -32,15 +37,21 @@ function upyun_upload.upload(filepath, filename)
local savePath = bucket .. "/" .. directory .. "/" .. filename local savePath = bucket .. "/" .. directory .. "/" .. filename
ngx.log(ngx.INFO, " savePath " , savePath) ngx.log(ngx.INFO, " savePath " , savePath)
local info, err = upyun:upload_file(savePath, nil, nil) local options = {
md5 = true
}
local info, err = upyun:upload_file(savePath, nil, options)
if not info then if not info then
ngx.status = 502 ngx.status = 400
ngx.log(ngx.ERR, "failed to upload file : " .. err) ngx.log(ngx.ERR, "failed to upload file : " .. err)
return return
else else
ngx.status = 200 ngx.status = 200
local fullpath = ngx.var.upyun_domain .. "/" .. directory .. "/" .. filename local fullpath = ngx.var.upyun_domain .. "/" .. directory .. "/" .. filename
--local fullpath = "https://upyun.huiwings.cn" .. "/" .. directory .. "/" .. filename
ngx.log(ngx.INFO, "SUCCESS UPLOAD -> UPYUN URL -> ", fullpath) ngx.log(ngx.INFO, "SUCCESS UPLOAD -> UPYUN URL -> ", fullpath)
--ngx.say("SUCCESS UPLOAD -> UPYUN URL -> ", fullpath)
ngx.say(fullpath) ngx.say(fullpath)
end end
end end
+13
View File
@@ -0,0 +1,13 @@
--package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
package.path = package.path .. ';/Users/liyong/Code/AlchemyStudio/resty_functions/scripts/?.lua';
ngx.say('UPLOAD COMBINED IMAGE -> start')
local upyun_upload = require("lib.upyun_upload")
ngx.say('UPLOAD COMBINED IMAGE -> upyun_upload loaded')
--local fullpath = "/Users/liyong/Code/AlchemyStudio/resty_functions/test_files_dir/r2d2.jpeg";
local fullpath = "/Users/liyong/Code/AlchemyStudio/resty_functions/test_files_dir/e4938956-954f-4918-be7f-7b10278a9ca4.jpeg";
ngx.say('UPLOAD COMBINED IMAGE -> fullpath -> ', fullpath)
upyun_upload.upload(fullpath, nil)