Nios Community Wiki > Uploading files using boa and cgihtml

Uploading files using boa and cgihtml

 

For applications that need a user configuration file in order to execute, this file update may involve a complex procedure (ftp, telnet, Unix commands, ...) that is not accessible to a "simple user", ... or a customer.
Those lines decribe what I did to answer the question of target files update, using boa and the library "cgihtml".

Library cgihtml

The version of cgihtml that is available in the uClinux-dist at this time is outdated. I have submitted the patch to upgrade it: please, check if your distribution resume writers is up to date. If not, I recommend you apply the patch below. 
To summarize, if the version number that can be found in user/cgihtml/CHANGES is greater or equal to 1.69, all is ok.
Otherwise, do the following:

git apply --verbose 0001-user-cgithml-update-1.66-1.69.patch

Then, the library can be compiled with:

make user/cgihtml_only

This will produce the file user/cgihtml/cgihtml.a to be linked with your application.

Example of HTML page

This simple HTML page example shows how a single FORM permits to upload a file, and then to call the CGI-Program which will proceed the file.

<HTML>
<HEAD><TITLE>A test web page</TITLE></HEAD>
<BODY>
<H1>Test Page</H1>
<P>If you are seeing this custom writing page, then your web server is working, and now
you need to create some nice pages to replace this one :-).<P>
<H1>SW Upload</H1>
<FORM ACTION="/cgi-bin/mycgipgm" METHOD=POST ENCTYPE="multipart/form-data">
  <INPUT TYPE=file name="swimage" /> <BR />
  <INPUT TYPE=submit VALUE="Submit"> <INPUT TYPE=reset VALUE="Reset">
</FORM>
</BODY>
</HTML>

CGI-Program example

This CGI-Program example is very minimal, because it just displays the upload result.
Note that after its execution, the uploaded file remains in UPLOADDIR (see the "romfs update" section below). It is up to the program to remove the file after processing (stored in flash for e.g.).

#include <stdio.h>
#include <cgi-lib.h>
#include <html-lib.h>
int main()
{
  llist entries;
  char *value;
  html_header();
  if (read_cgi_input(&entries) <= 0 ||
      (value = cgi_val(entries, "swimage")) == 0)
    h1("<BR />Error: failed to read \"swimage\" CGI input...<BR />\n");
  else
  {
    printf("<BR><H1>File \"%s\" successfully uploaded!</H1>\n", value);
    if (strcmp(value, "zImage") == 0)
    {
      h1("OK, that is a zImage: need to store it in flash...<BR />\n");
    }
  }
  list_clear(&entries);
  h2("Back to the <A HREF=/>main menu</A>...\n");
  html_end();
  return 0;
}

Application's Makefile example

Here is the application's Makefile I'm using.
I think that explanations on how to add an application to the distribution can be found somewhere in the Wikis, but this works as a standalone project...

UCLINUX_DIST=/local/nios2-linux/uClinux-dist-ndk
LIB_CGIHTML=$(UCLINUX_DIST)/user/cgihtml
CC=nios2-linux-uclibc-gcc
CFLAGS= -I$(SRC_DIR) -I. -I$(LIB_CGIHTML) \
        -O2 -g  -Dlinux -D__linux__ -Dunix -D__uClinux__ -DEMBED \
        -fno-builtin -D__adjtimex=adjtimex
LDFLAGS= -Wl,-d -Wl,-elf2flt $(LIB_CGIHTML)/cgihtml.a
mycgipgm: mycgipgm.o
        $(CC) -o $@ $< $(LDFLAGS)
install:        mycgipgm
        cp mycgipgm $(UCLINUX_DIST)/vendors/Altera/nios2
clean:
        rm -f mycgipgm mycgipgm.o

 

To include all your changes into your zImage, you must follow these steps:

  • copy your HTML file(s) and your CGI-Program(s) into the dir vendors/Altera/nios2, and add the related lines in vendors/Altera/nios2/Makefile.
    $(ROMFSINST) /home/httpd/cgi-bin/mycgipgm     # for your CGI-Programs
    $(ROMFSINST) /home/httpd/index.html           # for your HTML pages
    $(ROMFSINST) /home/httpd/boa.conf             # for boa configuration
    Warning: if "generic cgi" is selected in make menuconfig / Customize Appl/Lib Settings / Miscellanous Configuration, the files index.html and boa.conf will be overrided by the files in vendors/Generic/httpd.
    You can obviously modify custom writing vendors/Generic/httpd/index.html, but, to get all my customizations located in the single vendors/Altera/nios2 directory, I have prefered to unselect this item.
  • because UPLOADDIR is defined to "/usr/tmp" in user/cgihtml/Makefile, the files you will upload will be stored there. You have thus to add usr/tmp to the ROMFS_DIR list, and the line
chmod 777 $(ROMFSINST)/usr/tmp

to the file vendors/Altera/nios2/Makefile.

OK, time for you to play with HTML and CGI-Programs: have fun!

PS: thanks to Endre who gave me the initial pointers...

 

 

romfs update

Tag page

Files 1

FileSizeDateAttached by 
 0001-user-cgihtml-update-1.66-1.69.patch
No description
21.2 kB01:50, 8 Dec 2008AdminActions
Viewing 7 of 7 comments: view all
Boa is so good when uploading files. This works so well for me. boca raton sedation dentist
Posted 02:49, 16 Feb 2010
About the cgi part, the CGI-Program example is very minimal, because it just displays the upload result. Mike from presentation skills website.
Posted 14:55, 25 Feb 2010
louis vuitton handbags and purses are known and recognized luis vuitton the world as items of extreme quality, respect, lv outlet and luxury. It is one of the most well known louis vutton in the world, with many imitators but only one of a kind design hand craftsmanship and attention to details. Louis Vuitton started louis vuitton bags trunks in 1854. In the early days, louis vuitton sold flat trunks to France’s Empress Eugenie
Posted 01:20, 9 Mar 2010
Looking for Cheap and Discount rolex sports watches Brands watches lous vuitton handbags gucci handbags herve leger dressor Wallets?
Posted 04:55, 15 Mar 2010
Gucci GG coated 'joy' mini boston bag 193604 White 151.20 Gucci GG coated 'joy' mini boston bag 193604 Black 151.20 Gucci diamond fabric 'crest boule' medium top handle bag 223938 184.80 Gucci GG coated 'joy' mini boston bag 193604 Yellow 151.20 Balenciaga Lambskin Leather Giant City Top Handle Bag 084328b Bl 169.60 Balenciaga Lambskin Leather Giant City Top Handle Bag 084328b De 169.60 Balenciaga Lambskin Leather Giant City Top Handle Bag 084328b De 169.60 Balenciaga Lambskin Leather Giant City Top Handle Bag 084328b Bl 169.60 Balenciaga Lambskin Leather Giant City Top Handle Bag 084328b De 169.60 Balenciaga Lambskin Leather Giant City Top Handle Bag 084328b De 169.60 Balenciaga Lambskin Leather Giant City Top Handle Bag 084328b Bi 169.60 Balenciaga Lambskin Leather Giant City Top Handle Bag 084328b De 169.60 Gucci GG coated 'joy' mini boston bag 193604 Coffee 151.20 Gucci GG coated 'joy' mini boston bag 193604 White 151.20 Gucci GG coated 'joy' mini boston bag 193604 Black 151.20 Gucci GG coated 'joy' medium boston bag 193603 White Red 208.00 Gucci adjustable 'crest boule' medium top handle bag 223930 Pink 124.00 Balenciaga Patent Leather Giant Work Bag 084824 207.20 Balenciaga Lambskin Leather Giant Part Time Bag 084828 Blue 175.20 Balenciaga Lambskin Leather Giant Part Time Bag 084828 Coffee 175.20 Balenciaga Lambskin Leather Giant Part Time Bag 084828 Deepblue 175.20 Balenciaga Lambskin Leather Giant Part Time Bag 084828 Bigred 175.20 Balenciaga Lambskin Leather Giant Part Time Bag 084828 Coffee 175.20
Posted 05:21, 15 Mar 2010
Welcome to TiffanySilvers.us. Here you can find hundreds of cheap and discounted tiffany silver jewellery, which are perfectly polished and tiffany letters and 925 silver marked. If you are not familiar with tiffany jewelry, you can shop by the top navigation, showed as tiffany rings,tiffany bracelets,tiffany pendants,tiffany necklaces,tiffany earrings,tiffany cuff links and etc. For tiffany fans, you can shop by collections to save your time. We classified our tiffany jewellery not only by collections, like Tiffany 1837, Return to Tiffany, Tiffany Notes and etc. but also by designers' collections, such as Elsa Peretti Open Heart, Elsa Peretti Bean, Frank Gehry Fish, Paloma Picasso Loving Heart and so on. Hope our efforts can be more convenient for you to shop here.

Titanium jewelry

has been an incontrovertible perfect gift idea. Here we have hundreds of cheap and discounted titanium jewelry including titanium rings,titanium bracelets,titanium necklaces,titanium earrings,titanium cufflinks and titanium wedding bands for your choice. All our titanium jewelry are perfectly polished, and shipped with classic black boxes and shopping bags.

Tiffany Bangles

Tiffany Bracelets

Tiffany Charms

Tiffany Cuff Links

Tiffany Earrings

Tiffany Necklaces

Tiffany Pendants

Tiffany Rings

Tiffany Sets

Tiffany Accessories

Posted 14:04, 20 Mar 2010
Viewing 7 of 7 comments: view all
You must login to post a comment.
SourceForge.net