diff --git a/file_upload/upload_image.lua b/file_upload/upload_image.lua index 36b7774..3d42697 100644 --- a/file_upload/upload_image.lua +++ b/file_upload/upload_image.lua @@ -8,9 +8,9 @@ local form, err = upload:new(chunk_size) local output_image_filename_uuid = uuid.generate(); + if not form then ngx.log(ngx.ERR, "failed to new upload: ", err) - ngx.say("failed to new upload: ", err) ngx.exit(500) end @@ -42,7 +42,7 @@ local upload_image_index = 1 while true do local typ, res, err = form:read() if not typ then - ngx.say("failed to read: ", err) + ngx.log(ngx.ERR, "failed to read: ", err) return end if typ == "header" then @@ -60,8 +60,7 @@ while true do local kvfile = string.split(seg, "=") upload_image_filename = string.sub(kvfile[2], 2, -2) - ngx.say(" -->> POST : Upload origin image is ", upload_image_filename) - ngx.say("\n") + ngx.log(ngx.INFO,"Upload origin image is ", upload_image_filename) if upload_image_filename then -- Save file name with generate uuid @@ -69,15 +68,13 @@ while true do save_image_filename = save_image_filename .. '.' .. upload_image_filename:match(".+%.(%w+)$") fileToSave = io.open(saveRootPath .. save_image_filename, "w+") if not fileToSave then - ngx.say(" Error: Failed to open file ", save_image_filename) + ngx.log(ngx.ERR, " Error: Failed to open file ", save_image_filename) return else - ngx.say("Open file ok ", save_image_filename) - ngx.say("\n") + ngx.log(ngx.INFO, "Open file ok ", save_image_filename) upload_image_table[upload_image_index] = saveRootPath .. save_image_filename .. " " - ngx.say("Insert upload image table "..upload_image_index.." with "..upload_image_table[upload_image_index]) - ngx.say("\n") + ngx.log(ngx.INFO, "Insert upload image table "..upload_image_index.." with "..upload_image_table[upload_image_index]) upload_image_index = upload_image_index + 1 end @@ -107,36 +104,32 @@ while true do end end if ret_save then - ngx.say("Show all upload files\n") + ngx.log(ngx.INFO, "Show all upload files\n") -- Show all upload files upload_image_index = upload_image_index -1 for i = 1, upload_image_index do - ngx.say("Save upload file is : " .. upload_image_table[i]) - ngx.say("\n") + ngx.log(ngx.INFO, "Save upload file is : " .. upload_image_table[i]) end image_append_coroutine = coroutine.create( function () -- Append images - -- ngx.say("Upload image number is : " , upload_image_index ) + -- ngx.log(ngx.INFO,"Upload image number is : " , upload_image_index ) local append_images_path append_images_path = table.concat(upload_image_table) - ngx.say("Input images list : " , append_images_path) - ngx.say("\n") + ngx.log(ngx.INFO, "Input images list : " , append_images_path) -- local append_output_image = saveRootPath .. uuid.generate()..".jpg "; local append_output_image = saveRootPath .. output_image_filename_uuid..".jpg "; - ngx.say("Output image is : "..append_output_image) - ngx.say("\n") + ngx.log(ngx.INFO, "Output image is : "..append_output_image) -- Debug - ngx.say('/usr/local/ImageMagick/bin/magick convert -append '..append_images_path..' '..append_output_image) - ngx.say("\n") + ngx.log(ngx.INFO, '/usr/local/ImageMagick/bin/magick convert -append '..append_images_path..' '..append_output_image) local call_imagemagick_cmd = io.popen('/usr/local/ImageMagick/bin/magick convert -append '..append_images_path..' '..append_output_image) local imagemagick_cmd_replay = call_imagemagick_cmd:read("*all") - ngx.say(imagemagick_cmd_replay) + ngx.log(ngx.INFO, imagemagick_cmd_replay) end