openresty / openresty/lua-nginx-module

Using nginx upload module and nginx lua together

Open
#1,638 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

I am using nginx upload module for uplaoding files to server. But I wanted nginx to upload to different paths, not to a path mentioned in upload_store.
So I am taking help of nginx-lua module to change the upload_store value on each request like below.

location /umtest {
            upload_pass /nginx_response;
            set $upload_store '';
            rewrite_by_lua '
                local header = ngx.req.raw_header()
                ngx.say("type header",header)
                dst_path_dir = ngx.req.get_headers()["Dst-Dir"]
                ngx.say("dst_path_dir",dst_path_dir)
                ngx.var.upload_store = dst_path_dir
                ngx.say("upload store path" ,ngx.var.upload_store)    
             ';
                upload_set_form_field $upload_field_name.name 
               "$upload_file_name";
                upload_set_form_field $upload_field_name.content_type 
                "$upload_content_type";
                upload_set_form_field $upload_field_name.path 
                "$upload_tmp_path"
                upload_cleanup 400 404 499 500-505;
               }

Now when I POST to the '/umtest' it will change the upload_store value, but it will not execute the nginx upload direcives (i.e., upload will not happen). When I comment the rewrite_by_lua directive , the upload happens.
My question is cant we use both at a same time to achieve the purpose?

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 with the nginx configuration for location /umtest, especially rewrite_by_lua, upload_pass, upload_store, and the upload directives. Reproduce the POST with rewrite_by_lua enabled and disabled, then inspect how the Lua rewrite phase interacts with the nginx upload module. Done means establishing whether both can run together for the requested path selection, or documenting the limitation if they cannot.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.