Skip to content

bad argument #1 to 'rawget' (table expected, got string) #31

Description

@fqtrnt

I am new to lua.
A case, i was built a nginx + luajit +redis2.
I was used json.lua and got follow errer message:

2021/02/07 08:42:02 [error] 37#37: *11 failed to run body_filter_by_lua*: /etc/nginx/redis.lua:238: bad argument #1 to 'rawget' (table expected, got string)
stack traceback:
	[C]: in function 'rawget'
	/etc/nginx/redis.lua:238: in function 'decode'
	/etc/nginx/ueditor/ueditor_upload_file_rewrite_response.lua:22: in function </etc/nginx/ueditor/ueditor_upload_file_rewrite_response.lua:1> 

code fragments

if eof then
    local whole = table.concat(ngx.ctx.buffered)
    local ret_body = whole
    if whole then
        ngx.ctx.buffered = nil
        local body_json = json.decode(whole)     #################### line number 22 ####################
        local ret_table = {}
        if body_json then
            ret_table['original'] = body_json['originalFilename']
            ret_table['size'] = body_json['size']
            ret_table['state'] = 'SUCCESS'
            ret_table['title'] = body_json['originalFilename']:match("(.+)%.%w+$")
            ret_table['type'] = body_json['file']:match(".+(%.%w+)$")
            local imageUrl = body_json['thumbnail']
            if imageUrl and imageUrl ~= "" then
                ret_table['url'] = imageUrl
            else
                ret_table['url'] = body_json["file"]
            end
        else
            ret_table['state'] = 'Error: upload file failed!'
        end
        ret_body = json.encode(ret_table)
    end
    ngx.arg[1] = ret_body
end

Any help appreciated .
Thanks,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions