openresty / openresty/lua-resty-upload

Attempt to index local 'form' (a nil value)

Open
#26 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
414
Forks
110
Avg merge
2h 43m
Merged PRs (30d)
1

Description

Hi,
I am following below code on fedora Linux with nginx:

        local resty_sha256 = require "resty.sha256"
        local upload = require "resty.upload"

        local chunk_size = 4096
        local form = upload:new(chunk_size)
        local sha256 = resty_sha256:new()
        local file

        local upload_path = '/tmp/uploads/'


        while true do
           local typ, res, err = form:read()

            if not typ then
                ngx.say("failed to read: ", err)
                return
            end

            if typ == "header" then
                local file_name = upload_path .. ngx.time()
                if file_name then
                    file = io.open(file_name, 'w+')
                    if not file then
                        ngx.say("failed to open file ", file_name)
                        return
                    end
                end
            elseif typ == "body" then
                if file then
                    file:write(res)
                    sha256:update(res)
                end
            elseif typ == "part_end" then
                file:close()
                file = nil
            elseif typ == "eof" then
                break
            else
                -- nothing
            end
        end

        local digest = sha256:final()
        sha256:reset()

        local str = require "resty.string"
        ngx.say("sha256: ", str.to_hex(digest))```

When I run this as

curl -F "filename=@shatest.lua" http://127.0.0.1:8089/uploadtest

It gives me below errors:

$ tail -f /usr/local/openresty/nginx/logs/error.log 2016/06/29 15:26:23 [error] 31449#0: *12 lua entry thread aborted: runtime error: /usr/local/openresty/nginx/uploadtest.lua:13: attempt to index local 'form' (a nil value) stack traceback: coroutine 0: /usr/local/openresty/nginx/uploadtest.lua: in function </usr/local/openresty/nginx/uploadtest.lua:1>, client: 127.0.0.1, server: localhost, request: "POST /uploadtest HTTP/1.1", host: "127.0.0.1:8089"

Can you please help me what is wrong here?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report using uploadtest.lua, the shown curl command, and the Fedora/nginx setup. Start at line 13 where form:read() is called and inspect how resty.upload is required and initialized; done means identifying why form is nil and documenting a verified resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.