martini-contrib / binding

Martini handler for mapping and validating a raw request into a structure.
MIT License
140 stars 45 forks source link

map form files #10

Closed joaojeronimo closed 10 years ago

joaojeronimo commented 10 years ago

I needed this to map files in a form to strings in a structure so I added the function mapFormFiles that does that. It mimics hapi's payload parse.

Disclaimer: I don't know what I'm doing, never used reflect before, don't even know how it works. What I'd like this pull request to do is map a file in the form to some kind of io.Reader in a struct, but in my special case I would also like to accept the same kind of field as JSON string. It also has no idea if the file is a text file or not.

It's probably not ready to be accepted as is, but it's under way.

mholt commented 10 years ago

Sorry I'm late getting to this -- I'll look it over as soon as I have a chance. Meanwhile, I'm not familiar with hapi -- can you help me understand what this does better? Is it different than the recent PR #5 which supports file uploads using MultipartForm?

Or is this something where you specify the filename in your form submission and the Go appl loads the file into the struct with an io.Reader?

joaojeronimo commented 10 years ago

Hi, I didn't see #5, it's your second option. #5 might be better since you don't want to load all the contents of a file into RAM all the time, but I will keep using my fork because if I used the type *multipart.FileHeader in the struct then I'd have to use different structs for the same resource and that's a mess.

mholt commented 10 years ago

Okay, that'll be fine. I'm going to close this, but props for contributing! Someday we'll see your green teddy bear be replaced by the blue gopher. ;)