openresty / openresty/lua-resty-upload

form read size bigger than the real data length

Open
#22 1 comment 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

here is the code


local upload    =   require "resty.upload"
local json      =   require "cjson"
local s3_upload =   require "resty.s3_upload"

local form, err = upload:new(chunk_size)
if not form then
    ngx.log(ngx.ERR, "failed to new upload: ", err)
    ngx.exit(500)
end

local timeOut       =   10000
form:set_timeout(timeOut) 

while true do
        local typ, res, err = form:read()
        if not typ then
            ngx.say(ngx.ERR,"failed to read: ", err)
            return
        end 

        if typ == "header" then 
            content_type    =   res[2]
            if content_type  == 'application/hta' then 
                    start_upload    =   true
            end 
            ngx.log(ngx.INFO,"content_type: ", content_type)

            ngx.log(ngx.INFO,"header: ", json.encode(res))

        elseif typ == "body" then
            if start_upload==true and res then
                appender    =   appender..res
            end

        elseif typ == "part_end" then 

            if appender ~= ''  then
                local data_len  =    string_len(appender)
                ngx.log(ngx.NOTICE,"start to upload ",content_type," len=" ,data_len)
                ## -- ERROR HERE  handle string appender 
                ## -- data_len  is   bigger than I expected when the chunk_size is 50*1024
                               ##  -- data_len  will bi right when I change the chunk_size as 10*1024 
                ## -- if I post a file in the form 
                ## -- the data_len appender will be 15 byte bigger than the file I posted

                appender        =   ''
                start_upload    =   false
            end 

    elseif typ == "eof" then
         break 
    end 
end 

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

Start by reproducing the upload with the shown resty.upload usage, comparing appender length with the posted file length at different chunk_size values. Trace form:read() through the multipart parsing behavior and determine why the completed body includes extra bytes; done means the reported length matches the uploaded data across both chunk sizes.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.