Lua download POST request

I working with Corona and like to create a server that can store data that comes posted by a ordinary browser.

I am at the Point where I get the "POST" sequence and now would just need to store the incoming data.

some problems. After the Post I do not just get the file, first are coming several headers and a "content-type" with a boundary= Info like "----WebKitFormBoundary1AA ..."

For now I try to analyze each single Line I get for the first beginning of that boundary sequence and the second time (end boundary). My Code looks quiet messed up and I am sure there should be an easier option. Should U have a Solution, please post.

Thanks Chris

Here my code that is handled in a loop

_in loop after no error from: local request, err = client:receive()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
if request:sub(1,4) == "POST" then
    print ("GOT DATA UPLOAD")
 
    request,err = client:receive()
    local state = 0
    local lastdummy = ""
 
    while state ~= 3 and not err do
            request,err = client:receive()
 
        -- data between bounderies
        if state == 2 then 
            if request == "\r" then print ("----OK"); end
 
            print (request)
 
        end
 
            if state == 0 and request:sub(1,13) == "Content-Type:" then
            a,b = string.find (request, "boundary=")
            if a > 0 then
                lastdummy = (string.sub(request,b+1))   
                state = 1
            end
        elseif state == 1 then
            if request == "--"..lastdummy then
                print ("startttt")
                state = 2
            end
        elseif state == 2 then
            if request == "--"..lastdummy then
                print ("ENNNNND")
                state = 3
            end     
        end
 
    end
    state = 0
    print ("done")
end
views:1777 update:2011/10/18 8:54:01
corona forums © 2003-2011