I have a web appliction running in Tomcat (using Struts2). The Tomcat is running behind the Apache server.
I have a use case where I have to upload a file. The functionality is working fine if I access the application directly on Tomcat (IP address:8080). But when I access the application through Apache, the uploaded file is not available to tomcat.
OK. You've got me confused. When you upload via a JEE webapp server such as Tomcat, you don't get a "File Object". You have a variable in the HTTP POST sent to Tomcat (via Apache or not) that corresponds to the file upload HTTP control (<input type="file") on the client's web form. The receiving servlet can then use getPart to obtain a reference to an object that can return the user-selected upload filename and the file contents,
HTTP is not a file server. When you "upload/download" a file via HTTP, you don't actually do filesystem operations. Instead the data contained within the file in question is copied as a MIME component over the HTTP Request or Response stream.
So again, there is no file. To store the uploaded data on your webserver's filesystem, you have to obtain it as a data stream using the Part's getInputStream() method and then create a local File and write to it. Or, if your needs demand it, output it to a BLOB in a database. Or just scan the data stream and pull out the parts that interest you for further processing.
The underlyng file upload mechanism for HTTP is as I've described it. However, Struts does copy the uploaded data stream into a temporary File if you use Struts FileUploadAction. You would then have to figure out what to do with that temporary file, since in many cases in Jaava, temporary files can be set to delete themselves automatically. Raw HTTP file uploads don't actually ever have to live in a file - if the webapp server wants to, it can keep the data stream in RAM, but Struts itself can make a file out of it.
But Its not working if I access the application via Apache 4 , that is is Apache 4 --> Tomcat 9 --> Struts. Means when I access the application like https://myipaddress:80/uploadfile the fileUpload is null.