save image to uuid name
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ ngx.say(combined_uuid)
|
|||||||
--
|
--
|
||||||
-- ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
|
-- ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
|
||||||
--
|
--
|
||||||
-- upyun_upload.upload(combined)
|
-- upyun_upload.upload(combined, nil)
|
||||||
-- else
|
-- else
|
||||||
-- ngx.status = 500
|
-- ngx.status = 500
|
||||||
-- ngx.log(ngx.ERR, "IMAGE COMBINE *FAILED*")
|
-- ngx.log(ngx.ERR, "IMAGE COMBINE *FAILED*")
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ local function convert()
|
|||||||
local result, _, code = os.execute(cmd)
|
local result, _, code = os.execute(cmd)
|
||||||
if result and code == 0 then
|
if result and code == 0 then
|
||||||
ngx.log(ngx.INFO, "result -> ", result);
|
ngx.log(ngx.INFO, "result -> ", result);
|
||||||
upyun_upload.upload(converted_audio_file)
|
upyun_upload.upload(converted_audio_file, nil);
|
||||||
else
|
else
|
||||||
ngx.status = 500
|
ngx.status = 500
|
||||||
ngx.log(ngx.ERR, "AUDIO CONVERT *FAILED*")
|
ngx.log(ngx.ERR, "AUDIO CONVERT *FAILED*")
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ local fullpath = file_dir .. "/" .. file_to_upload .. ".jpeg";
|
|||||||
|
|
||||||
ngx.log(ngx.INFO, 'UPLOAD COMBINED IMAGE -> fullpath -> ', fullpath)
|
ngx.log(ngx.INFO, 'UPLOAD COMBINED IMAGE -> fullpath -> ', fullpath)
|
||||||
|
|
||||||
upyun_upload.upload(fullpath)
|
upyun_upload.upload(fullpath, nil)
|
||||||
@@ -7,7 +7,7 @@ local upyun_upload = {}
|
|||||||
local strip_path = require("strip_path")
|
local strip_path = require("strip_path")
|
||||||
local Upyun = require('upyun')
|
local Upyun = require('upyun')
|
||||||
|
|
||||||
function upyun_upload.upload(filepath)
|
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,
|
||||||
@@ -22,7 +22,9 @@ function upyun_upload.upload(filepath)
|
|||||||
|
|
||||||
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 filename = strip_path.strip_path(filepath)
|
if not filename then
|
||||||
|
filename = strip_path.strip_path(filepath)
|
||||||
|
end
|
||||||
|
|
||||||
local savePath = bucket .. "/" .. directory .. "/" .. filename
|
local savePath = bucket .. "/" .. directory .. "/" .. filename
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
local cjson = require "cjson"
|
local cjson = require "cjson"
|
||||||
local http = require "resty.http"
|
local http = require "resty.http"
|
||||||
local pl = require "pl.pretty"
|
local pl = require "pl.pretty"
|
||||||
|
|
||||||
local httpc = http.new()
|
local httpc = http.new()
|
||||||
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
||||||
local htyhostHeader = ngx.req.get_headers().HtyHost
|
local htyhostHeader = ngx.req.get_headers().HtyHost
|
||||||
@@ -75,7 +74,7 @@ local function get_wx_media(media_id)
|
|||||||
ngx.exit(res.status)
|
ngx.exit(res.status)
|
||||||
end
|
end
|
||||||
|
|
||||||
local filename = ngx.re.match(res.headers['Content-disposition'], [[filename="(.+\.([a-zA-Z0-9)+)"]], "jo")[1]
|
local filename = ngx.re.match(res.headers['Content-disposition'], [[filename="(.+\.([a-zA-Z0-9])+)"]], "jo")[1]
|
||||||
local file_dir = ngx.var.tmp_file_dir
|
local file_dir = ngx.var.tmp_file_dir
|
||||||
local saved_file = file_dir .. "/" .. filename;
|
local saved_file = file_dir .. "/" .. filename;
|
||||||
print('saved file...' .. saved_file);
|
print('saved file...' .. saved_file);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||||
|
|
||||||
local cjson = require "cjson"
|
local cjson = require "cjson"
|
||||||
|
local uuid = require "resty.jit-uuid"
|
||||||
local upyun_upload = require("upyun_upload")
|
local upyun_upload = require("upyun_upload")
|
||||||
local get_wx_media = require("wx_download")
|
local get_wx_media = require("wx_download")
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ local function run()
|
|||||||
|
|
||||||
local downloaded_file = get_wx_media(req_body["media_id"]);
|
local downloaded_file = get_wx_media(req_body["media_id"]);
|
||||||
|
|
||||||
upyun_upload.upload(downloaded_file)
|
upyun_upload.upload(downloaded_file, uuid.generate_v4() .. ".jpg")
|
||||||
end
|
end
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|||||||
Reference in New Issue
Block a user