I looked up one of my older projects, even logged into their application and did a download.
Works wonderful from a public server + remote client
The code that makes it work:
function downloadFile(event)
{
var _rec = foundset.getSelectedRecord();
var _file = _rec.file_path_relative;
var _jsFile = plugins.file.convertToRemoteJSFile(_file);
plugins.file.writeFile(_rec.file_name, _jsFile.getBytes(), _rec.file_extension);
}
Where the ‘file_path_relative’ column has stored something like this:
This is the relative path to the default upload path of the server
I think this is the area where your issue could be: trying to download an absolute path which doesn’t make sense if your on a remote client (browser in this case)
It works fine on a Azure-hosted test server with the same directory structure - I think something in the network setup is causing something in the Servoy stack to go wrong.
what is exactly your setup?
I think you have a tomcat and in front of that you have another firewall/proxy server?
And that proxy server talks to tomcat by tomcats internal ip?
Problem is that when you serve files to the browser we need to make it a full absolute url
what we do then is get the request url of tomcat (so the incoming url) and prepend that in front of the relative url (that points to that pdf)
But if you have a proxy/firewall server in front of this that talks to the tomcat server through its local ip then tomcat gives us that and we prepend the local ip
The thing is that the proxy/firewall should rewrite this. There should be rewrite rules somewhere where it sees certain ip adresses in the responses it should rewrite it to the public one.
the biggest problem here that it is not really a http header or a real redirect
Because this url is in the content, its in an ajax request that looks like this (you can see this in the chrome network inspector)
there you see that “showurl” that has in my example localhost:8080
So currently you have to have some rewrite rull that rewrites that too the public ip…
We could if needed do this rewrite maybe in servoy, where you then say in a property on the admin page what the public ip should be.
Or maybe this is also set in the headers somehow where we could potentally extract it (not sure if that is always the case)
The topology is possibly slightly unusual in that it is a Windows Server 2008 server that is hosting Servoy. It has a publicly visible IP address which end users hit, however it also is on the client’s LAN with a private IP. So WriteFile() seems to be favouring the private IP when building the URL for the browser, and there is no mechanism for overriding this within the Servoy stack.
Providing an Servoy admin page setting to provide the public IP would be great, do I have to file that as a request?
Okay, it turns out that the server is behind a product called Sophos UTM Web Server Protection. This has a per-server ‘pass host header’ setting which was disabled but when enabled appears to have solved thr problem, and WriteFile() acts as expected in this scenario.
When it’s not permissions, it’s always a bloody firewall or something.