diff --git a/test_files_dir/r2d2.jpeg b/test_files_dir/r2d2.jpeg new file mode 100644 index 0000000..48bbe6f Binary files /dev/null and b/test_files_dir/r2d2.jpeg differ diff --git a/test_upyun_upload.lua b/test_upyun_upload.lua new file mode 100644 index 0000000..60d9c7b --- /dev/null +++ b/test_upyun_upload.lua @@ -0,0 +1,19 @@ +local yun = require("upyun") + +local config = { + user = "moicen", --授权操作员名称 + passwd = "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN", --操作员密码 + localFilePath = "/Users/liyong/Code/Lua/resty_functions/test_files_dir/r2d2.jpeg" +} + +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 +end diff --git a/upyun.lua b/upyun.lua index f7c5f90..ef58ee3 100644 --- a/upyun.lua +++ b/upyun.lua @@ -270,6 +270,8 @@ local function _request(sock, method, path, headers, body, extra) local host = headers.Host if not sock then return nil, "not initialized yet" + else + print("Connect host : ", host) end sock:settimeout(5000) @@ -280,6 +282,11 @@ 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) + local header = _req_header(method, path, headers, extra) local bytes, err = sock:send(header) if not bytes then @@ -513,6 +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; if not user or type(user) ~= "string" or user == "" then return nil, "invalid user" @@ -536,9 +544,11 @@ 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() + --read_body() + --local content = get_body_data() + --local file = ngx.req.get_body_file() + local file = localFilePath; + local content = nil; if file then local f, err = io.open(file, "r") if not f then @@ -549,9 +559,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())