Comments (10)
@johnmuhl, this is currently not supported, but this is something I plan on adding shortly. In the meantime you should be able to use https://github.com/Kong/lua-multipart, but keep in mind that I plan to provide a more transparent API with the current params implementation, so that it's integrated with the rest of the checks and logic in the library. It's likely though that GetBody
will still return the submitted MIME message, so using other libraries will still work. I'll keep the ticket open and update it when the new implementation is available.
from fullmoon.
Thanks for the pointer to lua-multipart. That works for now. Will keep an eye out for the fm implementation.
from fullmoon.
@johnmuhl, how do you expect to access the headers (or any additional details like the filename)? It's convenient to return just one value (so r.params.myfieldname
returns the fileitself), but then the name and other header values are not easily available. I'm thinking about returning a table, which would then allow .value
field to access its value and .filename
field to access the filename (in addition to the rest of the headers).
from fullmoon.
I'm really new to lua so I'm not sure what is idiomatic or the obvious thing yet but a table sounds good to me. Using the multipart library I ran into exactly the problem you describe with returning just one value. I ended up with something like:
local mp = multipart(r.body, content_type)
local images = mp:get_as_array("images")
for i, _i in pairs(mp._data.indexes["images"]) do
-- _data is some internal structure
local ct, ex = mp._data.data[_i].headers[2]:match("^Content%-Type%:%s(.-)%/(.-)$")
-- image is the raw file content
local image = images[i]
end
There is probably a better way but I got the idea from their tests after struggling to figure it out.
In rack
(for ruby) you get an array of hashes with { type, filename, tempfile }
(and a couple of others) and it works out nicely. You do have to name the input like <input name="images[]"...>
for multiple
so it knows to handle those params differently (without the []
you just get a hash of type, etc). I think my first thought was to try something like:
for k, v in pairs(r.params.images) do
-- poke around hoping to find
-- v.headers, v.data, etc.
end
from fullmoon.
for k, v in pairs(r.params.images) do
-- poke around hoping to find
-- v.headers, v.data, etc.
end
Yes, that's exactly how it's working today, but I think there is still some advantage in returning the exact value, as it would allow using multipart parameters in route filters. So, I'm still debating whether r.params.myname
would return the value itself and r.params.multipart.myname
would return a table with all the details (including filename and the headers). If I can't get this to work for some reason, I'll keep the current implementation.
I also added support for params.images
in addition to params["images[]"]
based on your suggestion.
from fullmoon.
@johnmuhl, pushed the changes along with the documentation. It should work exactly as you listed (and the parameter filtering should work as well). Can you give it a try and let me know if something needs to be adjusted or added to the documentation?
from fullmoon.
Works great. I had to change:
https://github.com/pkulchenko/fullmoon/blob/master/fullmoon.lua#L1287
to return m and m.data or m
to avoid an "attempt to index nil value" error but haven't tracked down why I need that yet.
from fullmoon.
I think you're right; it may be a bug. I suspect it's supposed to be if m then return m.data or m end
, as it should still allow the fall-through to other keys (not present in the multipart messages). I'll confirm with tests and push a fix later today.
from fullmoon.
to return m and m.data or m to avoid an "attempt to index nil value" error but haven't tracked down why I need that yet.
@johnmuhl, this should be fixed now. Can you confirm when you get a chance? Thanks!
from fullmoon.
Yep that fixed it. Thanks again.
from fullmoon.
Related Issues (20)
- Any help with DNS/virtual hosting/ip address? HOT 3
- serveRedirect parameter order HOT 1
- [Suggestion] Disable Listing HOT 4
- [Suggestion] Built-in DDOS Protection HOT 3
- Processing layouts HOT 6
- multipart form validation HOT 4
- using booleans in oneof rules HOT 2
- In the instructions: "curl -o redbean.com https://justine.lol/redbean/redbean-latest.com" does not work HOT 3
- makeStorage support for in memory database HOT 4
- Does setTemplate support fmg table in lua code directly HOT 9
- Provide DB synchronization HOT 1
- Usage of makeStorage in requests HOT 16
- [Feature Request] To add automatic letsencrypt DNS-01 challenge just like caddy web server HOT 4
- [Feature Request] CSRF protection HOT 2
- call Redbean API functions from template HOT 1
- Reading a cookie that has not been set causes an error HOT 5
- Index using 2 different hosts HOT 3
- [Feature Request] Grouping variables passed to the template to be passed in the render HOT 2
- How to merge newest changes of Fullmoon, SQLite etc? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fullmoon.