Skip to content

form read size bigger than the real data length #22

@lilien1010

Description

@lilien1010

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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions