Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fqtrnt opened this issue Feb 7, 2021 · 0 comments
Open

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

fqtrnt opened this issue Feb 7, 2021 · 0 comments

Comments

@fqtrnt
Copy link

fqtrnt commented Feb 7, 2021

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant