clean up
This commit is contained in:
+21
-13
@@ -1,19 +1,27 @@
|
||||
local yun = require("upyun")
|
||||
|
||||
local config = {
|
||||
user = "moicen", --授权操作员名称
|
||||
passwd = "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN", --操作员密码
|
||||
localFilePath = "/Users/liyong/Code/Lua/resty_functions/test_files_dir/r2d2.jpeg"
|
||||
}
|
||||
local function upyun_upload_file()
|
||||
|
||||
local upyun = yun:new(config)
|
||||
local config = {
|
||||
user = "moicen", --授权操作员名称
|
||||
passwd = "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN", --操作员密码
|
||||
localFilePath = "/Users/liyong/Code/Lua/resty_functions/test_files_dir/r2d2.jpeg"
|
||||
}
|
||||
|
||||
local savePath = "huiwing/test/r2d2.jpeg"
|
||||
local gmkerl = nil
|
||||
local options = nil
|
||||
local upyun = yun:new(config)
|
||||
|
||||
local savePath = "huiwing/test/r2d2.jpeg"
|
||||
local gmkerl = nil
|
||||
local options = nil
|
||||
|
||||
local info, err = upyun:upload_file(savePath, gmkerl, options)
|
||||
if not info then
|
||||
ngx.say("failed to upload image file : " .. err)
|
||||
return
|
||||
else
|
||||
ngx.say(info)
|
||||
end
|
||||
|
||||
local info, err = upyun:upload_file(savePath, gmkerl, options)
|
||||
if not info then
|
||||
ngx.say("failed to upload image file : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
upyun_upload_file()
|
||||
@@ -271,7 +271,7 @@ local function _request(sock, method, path, headers, body, extra)
|
||||
if not sock then
|
||||
return nil, "not initialized yet"
|
||||
else
|
||||
print("Connect host : ", host)
|
||||
print("Upyun module request connect host : ", host)
|
||||
end
|
||||
|
||||
sock:settimeout(5000)
|
||||
@@ -282,10 +282,10 @@ local function _request(sock, method, path, headers, body, extra)
|
||||
end
|
||||
|
||||
-- Build and send request header
|
||||
print("Debug header method : ", method)
|
||||
print("Debug header path : ", path)
|
||||
print("Debug header headers : ", headers)
|
||||
print("Debug header extra : ", extra)
|
||||
print("Debug upyun module request header method : ", method)
|
||||
print("Debug upyun module request header path : ", path)
|
||||
print("Debug upyun module request header headers : ", headers)
|
||||
print("Debug upyun module request header extra : ", extra)
|
||||
|
||||
local header = _req_header(method, path, headers, extra)
|
||||
local bytes, err = sock:send(header)
|
||||
@@ -520,7 +520,7 @@ function _M.new(self, config)
|
||||
local passwd = config.passwd
|
||||
local endpoint = config.endpoint and tonumber(config.endpoint) + 1 or 1
|
||||
local author = config.author and lower(config.author) or nil
|
||||
local localFilePath = config.localFilePath;
|
||||
local localFilePath = config.localFilePath or nil -- add config para for upload file directly
|
||||
|
||||
if not user or type(user) ~= "string" or user == "" then
|
||||
return nil, "invalid user"
|
||||
@@ -544,11 +544,18 @@ function _M.new(self, config)
|
||||
end
|
||||
|
||||
-- file to be uploaded is stored in the request body
|
||||
--read_body()
|
||||
--local content = get_body_data()
|
||||
--local file = ngx.req.get_body_file()
|
||||
local file = localFilePath;
|
||||
local content = nil;
|
||||
print("Upyun module new config para local file path : ", localFilePath)
|
||||
local file = nil
|
||||
local content = nil
|
||||
if localFilePath == nil then
|
||||
read_body()
|
||||
content = get_body_data()
|
||||
file = ngx.req.get_body_file()
|
||||
else
|
||||
file = localFilePath;
|
||||
end
|
||||
|
||||
print("Upyun module new config file : ", file)
|
||||
if file then
|
||||
local f, err = io.open(file, "r")
|
||||
if not f then
|
||||
@@ -559,9 +566,9 @@ function _M.new(self, config)
|
||||
f:close()
|
||||
end
|
||||
|
||||
if not content then
|
||||
return nil, "request body is expected"
|
||||
end
|
||||
--if not content then
|
||||
-- return nil, "request body is expected"
|
||||
--end
|
||||
|
||||
--TODO ngx.updatetime?
|
||||
local date = http_time(time_sec())
|
||||
@@ -629,17 +636,21 @@ function _M.upload_file(self, path, gmkerl, option)
|
||||
if not ret then
|
||||
return nil, err
|
||||
end
|
||||
print("Upyun module upload file request ret : ", ret)
|
||||
|
||||
print("Upyun module upload file parse response headers : ", ret)
|
||||
ret, err = _parse_upyun_headers(ret.headers, [[^x-upyun-([\w-]+)$]])
|
||||
if not ret then
|
||||
return nil, err
|
||||
end
|
||||
print("Upyun module upload file parse response headers ret : ", ret)
|
||||
|
||||
-- write the original author back as header.Authorization
|
||||
-- may be changed in the _upyun_request()
|
||||
headers.Authorization = author
|
||||
headers["Content-Length"] = "0"
|
||||
|
||||
print("Upyun module upload file ret : ", ret)
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user