Coder Social home page Coder Social logo

Comments (4)

agentzh avatar agentzh commented on July 17, 2024

@rhettli We have many production users doing large column of uploads with OpenResty. So I believe it's just mistakes in your own code. If you believe it's a bug in OpenResty, please provide a minimal and standalone example that we can easily run and reproduce the issue on our side. Otherwise we cannot help you with so little info since we are not gods. BTW, you can always join the openresty (Chinese) mailing list for discussions if you prefer Chinese: http://openresty.org/en/community.html

from lua-resty-upload.

rhettli avatar rhettli commented on July 17, 2024

maby many people use linux os to dev their project, I use windows xp to develop my project ,so the openresty of window have a problem(bug) that less people find it .i stick my config of nginx and upload code of lua here . please make sure if the openresty of windows have this bug which cause upload file to server can't be open. @agentzh

here is nginx config:

pid tmp/nginx.pid;

worker_processes 1;

events {
    worker_connections 4096;
}

http {
    sendfile on;
    include mime.types;
	#default_type  application/octet-stream;
	
    # lor initialization
    lua_package_path "app/?.lua;./?.lua;;";					#;/usr/local/lor/?.lua
    #lua_code_cache on;

    server {
        listen 8081;
        set $template_root '';
	# 加载静态文件,匹配到就不会往后匹配了。
    location  ~  /static {
        #alias app/views/static; #app/views/static;
        root  app/views;
    }
    location ~ /upload_ {#这里配置上传脚本路由。
        content_by_lua_file app/upload.lua;
    }
 	#主目录路由接入
    location  ~  / {
     		lua_code_cache  off;	#仅仅在调试的时候关闭,正式环境需要打开。
            content_by_lua_file ./app/main.lua;
    }
    access_log logs/dev-access.log;
    error_log logs/dev-error.log;

    }
}

and here is lua upload code(copy form net):

local upload = require ("resty.upload")
local chunk_size = 4096  --如果不设置默认是4096.
local form = upload:new(chunk_size)
local file
local filelen=0
form:set_timeout(1000) -- 1 sec

local osfilepath = "app/views/static/"  --文件默认的保存位置


function get_filename(res)
    local fname = ngx.re.match(res,'(.+)filename="(.+)"(.*)')
    if fname then
        return fname[2]
    end
end

  local i=0
  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
          if res[1] ~= "Content-Type" then 
              local filename = get_filename(res[2])
              if filename then
                  i=i+1
                  local filepath = osfilepath  .. filename
                  file = io.open(filepath,"w+")
                  if not file then
                      ngx.say("failed to open file ")
                      return
                  end
              else
              end
          end
      elseif typ == "body" then
          if file then
              filelen= filelen + tonumber(string.len(res))    
              file:write(res)
          else
          end
      elseif typ == "part_end" then
          if file then
              file:close()
              file = nil
              ngx.say("file upload success")
          end
      elseif typ == "eof" then
          break
      else
      end
  end
  
  
  if i==0 then --0123456789
      ngx.say("please upload at least one file!")
      return
  end
--return middleware

from lua-resty-upload.

agentzh avatar agentzh commented on July 17, 2024

@rhettli On Windows you should open the file as a binary file otherwise it treats it as a text file and writes extra bytes to the file automatically. Basically you should pass the "b" flag to the io.open() call.

from lua-resty-upload.

rhettli avatar rhettli commented on July 17, 2024

@agentzh thx,thank for your. help,this problem make me confusing 'my project delay long time.

I love lua and openresty.

from lua-resty-upload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.