AppWeb Forum

Support for the AppWeb HTTP Server
It is currently Thu Sep 09, 2010 5:24 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Help with file upload
PostPosted: Mon Mar 01, 2010 2:29 pm 
Offline

Joined: Wed Feb 10, 2010 10:10 am
Posts: 36
Hi,

I'm in difficulties with upload. Could you please explain the upload feature and post a working example? I see the example in ejs/upload folder but I don't understand if an egi handler is needed...

Thanks
Simone


Top
 Profile  
 
 Post subject: Re: Help with file upload
PostPosted: Wed Mar 03, 2010 5:03 am 
Offline
Site Admin

Joined: Wed Nov 19, 2003 11:42 pm
Posts: 1107
Location: Seattle, Washington
File upload works by using the Upload filter. This is a pipeline stage that intercepts incoming data.

If configured via the AddFilter/AddInputFilter directives to be valid for a request, it will receive data from the network and will remove all upload data content. It will create a temp file and write the upload data to that file.

The handler then receives form data but NOT any upload data. The upload filter will create some variables that describe where the temp files are and what is the size, name etc. The handler then runs.

If the handler invokes a script (ejs, php, cgi), then that script can read the variables and copy or move the temp file to a permanent location. If the script does nothing, then the upload filter will remove the temp file when the request completes.

Michael

_________________
Michael O'Brien
Lead Architect
Embedthis Software


Top
 Profile  
 
 Post subject: Re: Help with file upload
PostPosted: Wed Mar 03, 2010 7:58 am 
Offline

Joined: Wed Feb 10, 2010 10:10 am
Posts: 36
Hi,

So, if I understand, I need only to configure the appweb.conf file, provide a form to browse the file to be uploaded and attach the form with an handle that move the file; but what are these variables that the upload filter creates?
Thanks

Simone


Top
 Profile  
 
 Post subject: Re: Help with file upload
PostPosted: Thu Mar 18, 2010 4:27 pm 
Offline

Joined: Wed Feb 10, 2010 10:10 am
Posts: 36
Hi Mob

I have added directives to my server conf file, as described below:
Code:
#
#   dmtconf -- Appweb configuration for DMT web server
#   

<if LOG>
    ErrorLog server.log
    LogLevel 0
</if>

Listen          80        # MAIN - dont remove comment
DocumentRoot    "html/DMT_Equip/"
ServerRoot       .
DirectoryIndex    index.html
LoadModulePath    "../modules"
SetConnector    netConnector
DirectoryIndex    index.html
PutMethod       on
KeepAlive       off
Protocol       HTTP/1.1



# 1GB
LimitRequestBody     1000000000
LimitUploadSize      1000000000
LimitResponseBody    1000000000

<if AUTH_MODULE>
    LoadModule authFilter mod_auth
    AddOutputFilter authFilter
    AuthGroupFile groups.db
    AuthUserFile users.db
    AuthDigestQop auth
</if>

<if RANGE_MODULE>
    LoadModule rangeFilter mod_range
    AddOutputFilter rangeFilter
</if>
<if CHUNK_MODULE>
    LoadModule chunkFilter mod_chunk
    AddFilter chunkFilter
</if>

#<if UPLOAD_MODULE>
#    LoadModule uploadFilter mod_upload
#    UploadDir .
#    UploadAutoDelete on
#    AddInputFilter uploadFilter
#</if>

<if UPLOAD_MODULE>
    LoadModule uploadFilter mod_upload
    UploadDir /tmp/
    UploadAutoDelete on
   AddInputFilter uploadFilter
</if>

<Directory $DOCUMENT_ROOT/>
    AuthType basic
    AuthName "DMT Equip"
    Require valid-user
</Directory>
<if DIR_MODULE>
    LoadModule dirHandler mod_dir
    AddHandler dirHandler
    Options Indexes
    IndexOrder ascending name
    IndexOptions FancyIndexing FoldersFirst
</if>
<if EGI_MODULE>
    LoadModule egiHandler mod_egi
    AddHandler egiHandler .egi
</if>
<if EJS_MODULE>
    LoadModule ejsHandler mod_ejs
    AddHandler ejsHandler .ejs
    <Location /ejs/>
        SetHandler ejsHandler
    </Location>
    <Location upload/>
        SetHandler ejsHandler
    </Location>
    EjsErrors browser
    EjsSession on
    EjsSessionTimeout 300
</if>
<if PHP_MODULE>
    LoadModule phpHandler mod_php
    AddHandler phpHandler .php
</if>
<if FILE_MODULE>
    LoadModule fileHandler mod_file
    AddHandler fileHandler .html .gif .jpeg .png .pdf .js .css ""
</if>



In upoad.html page, the form invokes the next egi handler

Code:
void uploadFormEgi(MaQueue *q)
{
   MaConn      *conn;
   MaRequest   *req;
   MaUploadFile          *up;
   MprHash         *hp;
   char buff[256];
   conn = q->conn;
   mprAssert(conn);
   req = conn->request;
   mprAssert(req);
   
   maSetHeader(q->conn, 0, "Last-Modified", req->host->currentDate);
   maSetHeader(q->conn, 0, "Content-Type", "text/html");
   maDontCacheResponse(q->conn);
   maPutForService(q, maCreateHeaderPacket(q->conn), 0);
   maDontCacheResponse(conn);
   
   up = (MaUploadFile*) mprLookupHash(req->files, "upgradeFile");
   if (up) {
      sprintf(buff, "mv %s %s", up->filename, "/var/upload/image.bin");
      system(buff);
      mprFree(buff);
               maSetResponseCode(conn, 200);
       } else {
               maSetResponseCode(conn, 400);
      }
      maPutForService(q, maCreateEndPacket(q->conn), 1);
      return;
}


Size of the upoaded file is about 3 Mb. My server application works fine but sometimes it crashes (segmentation fault). Using debugger I see that crashes in maMatchHandler function.
Could you please tell if conf file and egi handler are right?
Thanks in advance for your suggestions and patience

Simone


Top
 Profile  
 
 Post subject: Re: Help with file upload
PostPosted: Fri Mar 19, 2010 12:59 am 
Offline

Joined: Sat Dec 31, 2005 1:16 am
Posts: 183
You seem to be freeing a static buffer.

Code:
mprFree(buf)


You may want to move your file using rename() or equivalents.

cjr


Top
 Profile  
 
 Post subject: Re: Help with file upload
PostPosted: Wed Jul 21, 2010 12:55 pm 
Offline

Joined: Wed Feb 10, 2010 10:10 am
Posts: 36
Hi all,
I have to upload large files so I would like to have an html page showing the percentage of the uploading file. I'm writing an egi handler but I'm a bit in difficulties.
How can I retrieve such information?
Thanks
Simone


Top
 Profile  
 
 Post subject: Re: Help with file upload
PostPosted: Fri Jul 30, 2010 1:57 am 
Offline
Site Admin

Joined: Wed Nov 19, 2003 11:42 pm
Posts: 1107
Location: Seattle, Washington
To do that you would need an ajax control in the client and a request that returned the percentage.

Basically you need to do some client side javascript using something like JQuery to submit background HTML requests (ajax style). Those requests go to the server which can return the % uploaded.

Michael

_________________
Michael O'Brien
Lead Architect
Embedthis Software


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
[ Time : 0.129s | 10 Queries | GZIP : Off ]