We have a web application that allows users to upload photos which will then be displayed in a specified page after upload. The upload module places the images inside the exploded war directory, e.g. webapp-root/uploads/ such that once the image is uploaded, it can be viewed instantly, as in http://mydomain.com/uploads/123.png.
This was working with one application server, but as it turns out, we were to deploy this app to 2 load-balanced servers. So I coded a quick file-sync module that syncs files between servers using FTP, whenever users upload images. Basically when a user uploads an image on server1/uploads/, I immediately copy it via FTP to server2/uploads/.
Edit (added upload process): The upload goes something like this:
- User selects and submits image
- Server saves file in
server1/uploads/ - Background thread does an FTP sync from server1 to
server2/uploads/(done async) - Vice versa for server2
At this point, I’m running into problems.
The url http://mydomain.com uses a hardware load balancer to point to either server1 or server2. If a user uploads an image test-image.png to server1 (which is then synced to server2), I assume that I can access the image through http://mydomain.com/uploads/test-image.png regardless of whether the load balancer directs me to server1 or server2.
This isn’t the case however. Continuing with the example, an image uploaded when the domain is pointed to server1 can only be viewed when http://mydomain.com/uploads/test-image.png is redirected to server1, and it appears as a broken link if a second user accesses the same url but the load balancer directs him to server2.
So it seems like JBoss isn’t refreshing the second server whenever I FTP-copy an image inside its war directory. Which is kind of weird since if I upload an image to server1, the JBoss instance on that server serves up the image file without any problems.
Any way to manually tell JBoss that “hey, we have a new image file here”?
I’ve narrowed the issue to corrupted files on the receiving server. It would seem like the file permissions/encryption on the particular drive are preventing my FTP server from copying the images successfully which is why all my synced images cannot be viewed in any image viewer.
I’ll have to try and resolve these user permission problems. Meanwhile I’ll keep this question open in case anyone can shed some more light on other probable causes.