Got a question regarding the upload library.
I’m making a multipart-form upload request. In the form there are several fields and I’m trying to get the field names.
A typical header:
Content-Disposition: form-data; name="filecomment"
And my code looks something like this:
local typ, res, err = form:read()
if typ == "header” then
local i, j = string.find(str, "name=\"%w*\”")
if i and j then
local field = res[2]:sub(tonumber(i)+6,tonumber(j)-1) —- should give me the field name
end
end
The problem is that I’m getting a 'attempt to perform arithmetic on a string value’ when calling the string.find() function.
Wonder if anyone know what is the problem with the code?
Attached is also the code.
Thanks so much for the help.
Joe
location /api/ {
proxy_pass http://localhost:8080;
}
location /upload/ {
content_by_lua '
local upload = require "resty.upload"
local cjson = require "cjson"
local chunk_size = 8192
local form, err = upload:new(chunk_size)
if not form then
ngx.log(ngx.ERR, "failed to new upload: ", err)
ngx.exit(500)
end
ngx.say("lua upload ready")
form:set_timeout(1000) -- 1 sec
while true do
local typ, res, err = form:read()
if not typ then
ngx.say("failed to read: ", err)
return
end
ngx.say("read: ", cjson.encode({typ, res}))
if typ == "eof" then
break
end
end
local typ, res, err = form:read()
ngx.say("read: ", cjson.encode({typ, res}))
';
}