I have a NET+OS-based web application but when I access files they are 0 (zero) length

Problem:
    You have developed a NET+OS-based application which includes the AWS web server and the application includes file system access. Maybe you have also included the FTP server. You find that you can put and get files successfully from the file system using an FTP client. On the other hand, when you try and access a file you placed on the file system using FTP through a web browser (using a web browser to ask the web server to get you a file from the NET+OS-based file system) the file you get is 0 (zero) length. How do you solve this? 

Analysis:
     The advanced web server (AWS) uses a file called file.c as its file system interface. If you look at the contents of file.c (src\rphttpd) you will see many APIs that deal with files, permissions, directories et al. What you will also notice is that the entire file is within a set of preprocessor directives as follows:
#ifdef APP_FILE_SYSTEM
and
#endif
     So what does this mean? It means that if APP_FILE_SYSTEM is NOT defined, the entire contents of the file file.c is a big no-op. If this file is a no-op then AWS uses its internal file system APIs that do nothing and thus return a zero-length file to you.

Defining the macro:
    Digi recommends the following procedure:
    In ESP: right click on your project
    Select properties
    Select C/C++ Build
    Click on the '>' to the left of C/C++ build
    Select Settings
    Select Symbols
    To the right of the phrase 'Defined Symbols' click the '+' sign
    An 'Enter Symbols' box appears
    In the box under the phrase 'Defined Symbols' type in APP_FILE_SYSTEM
    Click OK
    Click OK
    
    Next rebuild your application
    When you next run your application, the APIs in file.c will be enabled and the AWS will be able to access the file system. You should be able to access your files via a web browser.

    Remember also to enable the file system in bsp_fs.h by setting the definition of the macro BSP_INCLUDE_FILESYSTEM_FOR_CLIBRARY to TRUE. 
      

Conclusion:
    The file file.c is the file system interface for the AWS (web server) in NET+OS-based applications. What is not well documented is that the macro APP_FILE_SYSTEM MUST be defined to enable the APIs in file.c. Without this macro being defined, all of the APIs in file file.c are #ifdefed out and the web server is left using its default file system calls that do nothing.

    Hopefully this article explains this well enough to help you enable the file system for your AWS-enabled applications.
Last updated: Jan 01, 2024

Recently Viewed

No recently viewed articles

Did you find this article helpful?