I have successfully integrated Ignacio's code to my web application.

Thanks to Ignacio's good work.


2010/9/4 Ignacio Burgueño <iburgu...@gmail.com>

> On Fri, Sep 3, 2010 at 11:46 AM, Fabio Mascarenhas <mascaren...@acm.org>wrote:
>
>> More than a starting point, I think. The parse_message_body function
>> in this can be reused in an WSAPI program by making an LTN12 source
>> for wsapi_env.input, which should be easy, plus passing { env =
>> wsapi_env } as the msg parameter, and your file upload callback.
>>
>> The LTN12 module is part of LuaSocket.
>>
>
> I have written something like that. I think it goes along the lines of what
> you suggested.
>
> I think the following example assumes the POST is multipart/form-data
>
> function UploadHandler(wsapi_env)
> local request = wsapi.request_stream.new(wsapi_env)
>  local response = wsapi.response.new(200, { ["Content-Type"]= "text/plain"
> })
>  local file_sink, err = ltn12.sink.file( io.open(fullFileName, "wb") )
> if not file_sink then
>  response.status = 500
> response:write("Unable to save file to disk")
>  return response:finish()
> end
>  -- o Table containing decoded (name, file) and raw (headers) mime header
> data
> --  o String value containing a chunk of the file data
>  --  o Boolean which indicates wheather the current chunk is the last one
> (eof)
> local readBytes = 0
>  local mimeHeaders
> local callback = function( headers, chunk, last )
> if not mimeHeaders then
>  mimeHeaders = headers
> end
> readBytes = readBytes + #chunk
>  file_sink(chunk)
> if last then
> file_sink(nil)
>  end
> end
> request:parse_message_body( callback )
>  response:write(tostring(readBytes))
> return response:finish()
> end
>
> _______________________________________________
> Kepler-Project mailing list
> Kepler-Project@lists.luaforge.net
> http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
> http://www.keplerproject.org/
>
_______________________________________________
Kepler-Project mailing list
Kepler-Project@lists.luaforge.net
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/

Reply via email to