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

form read size bigger than the real data length #22

Open
lilien1010 opened this issue Jan 27, 2016 · 1 comment
Open

form read size bigger than the real data length #22

lilien1010 opened this issue Jan 27, 2016 · 1 comment

Comments

@lilien1010
Copy link

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 
@lilien1010 lilien1010 changed the title form fead size bigger than the real data form read size bigger than the real data length Jan 27, 2016
@agentzh
Copy link
Member

agentzh commented Jan 27, 2016

@lilien1010 Please give more detailed explanation on what problem you are reporting and better, with steps of reproducing the problem on our side. Simply giving a code listing is not really helpful. Thanks for your cooperation.

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

2 participants