save image to uuid name

This commit is contained in:
moicen
2022-06-26 17:49:50 +08:00
parent 46f27ba9d5
commit 6648a4f1ee
6 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ ngx.say(combined_uuid)
--
-- ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
--
-- upyun_upload.upload(combined)
-- upyun_upload.upload(combined, nil)
-- else
-- ngx.status = 500
-- ngx.log(ngx.ERR, "IMAGE COMBINE *FAILED*")
+1 -1
View File
@@ -27,7 +27,7 @@ local function convert()
local result, _, code = os.execute(cmd)
if result and code == 0 then
ngx.log(ngx.INFO, "result -> ", result);
upyun_upload.upload(converted_audio_file)
upyun_upload.upload(converted_audio_file, nil);
else
ngx.status = 500
ngx.log(ngx.ERR, "AUDIO CONVERT *FAILED*")
+1 -1
View File
@@ -11,4 +11,4 @@ local fullpath = file_dir .. "/" .. file_to_upload .. ".jpeg";
ngx.log(ngx.INFO, 'UPLOAD COMBINED IMAGE -> fullpath -> ', fullpath)
upyun_upload.upload(fullpath)
upyun_upload.upload(fullpath, nil)
+4 -2
View File
@@ -7,7 +7,7 @@ local upyun_upload = {}
local strip_path = require("strip_path")
local Upyun = require('upyun')
function upyun_upload.upload(filepath)
function upyun_upload.upload(filepath, filename)
local upyun, err = Upyun:new({
user = ngx.var.upyun_operator,
passwd = ngx.var.upyun_password,
@@ -22,7 +22,9 @@ function upyun_upload.upload(filepath)
local bucket = ngx.var.upyun_bucket
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
+1 -2
View File
@@ -1,7 +1,6 @@
local cjson = require "cjson"
local http = require "resty.http"
local pl = require "pl.pretty"
local httpc = http.new()
local sudoerToken = ngx.req.get_headers().HtySudoerToken
local htyhostHeader = ngx.req.get_headers().HtyHost
@@ -75,7 +74,7 @@ local function get_wx_media(media_id)
ngx.exit(res.status)
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 saved_file = file_dir .. "/" .. filename;
print('saved file...' .. saved_file);
+2 -1
View File
@@ -3,6 +3,7 @@
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
local cjson = require "cjson"
local uuid = require "resty.jit-uuid"
local upyun_upload = require("upyun_upload")
local get_wx_media = require("wx_download")
@@ -20,7 +21,7 @@ local function run()
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
run();