No announcement yet.

CGI code for file upload

  • Filter
  • Time
  • Show
Clear All
new posts

  • CGI code for file upload

    I am trying to use the SDK to do a file upload to the Lantronix and send it through the serial line to another part of the system. I am using the code in cgi.c as a starting point.

    To upload the file I am using the usual HTML code:

    <form method="post" enctype="multipart/form-data">
    <input type="file" name="datafile" size="40">
    <input type="submit" name="sa" value="Send">

    If I send a small file my cgi callback function is invoked, but if the file is too large the callback function is never invoked and the connection with the client is dropped.

    Question: What is the maximum file size I can send with a POST.


  • #2
    The maximum size for a post request can be configured using the HttpInit() function, demonstrated in the "secureweb.c" sample.

    You can also configure this size using the "Max Bytes" field in the "HTTP | Configuration" page of the Lantronix Web Manager.


    • #3
      I do not think the secureweb application is provided in the current version of the SDK. I know I have seen the file in a prior release, but I did not looked at it.


      • #4
        You are correct. My apologies. We pulled this sample near the end of our release cycle because we found a few problems with the API's it demonstrates. It will be back in the next release, however.

        I have excerpted the relevant section of code and enclosed it below. In your case, the HTTPS related parameters should either by NULL or zero.

        if (returnCode == 0 && (sdkHttp = HttpInit( FALSE, /* managed server */ NULL, /* destory callback */ 3, /* the number of worker threads */ "/", /* the website root directory */ "http/config/evolution_os_logo.gif", /* the website default page */ 12, /* max queue length */ 80, /* server port */ 10, /* server back log */ 10, /* request timeout in seconds */
        4096UL, /* maximum size of the post request */ 10, /* maximum number of dynamic callbacks */ 443, /* number of the https port */ SSL3_VERSION_BIT | TLS1_0_VERSION_BIT | TLS1_1_VERSION_BIT, /* the type of https protocols to use */
        certAndKeyList /* the RSA and DSS certificates generated above */
        )) != NULL)
        { /*
        * Make this newly created default server the default so that all XML * imports are properly applied. */ HttpDefaultServerSet(sdkHttp);
        * Add a CGI callback for the /info URL. */ HttpDynamicCallbackAdd(sdkHttp, "/info", SdkHttpInfoCbk); . . .


        • #5
          I'm having trouble uploading a file as well.

          How do I read the multipart-form data? Your API suggests data gets put into a struct called "list", however nothing in your API tells us how to read the data in the list. Your API doesn't reference the data part of your linked lists, just pointers to the next and prev. How's that?