02-22-2011 08:23 AM
I'm not sure what you're asking for. By local do you mean local to the server or local to the client? When I hear "hyperlink to a local file", I tend to think of a "file://" url. But if the file is on the user's machine, then they don't need to download it.
Are you really trying to access a file on the user's machine or are you trying to give them a link that prompts to save the file locally? For the latter, is the file static content that you could just publish to your web server or will its contents change over time?
03-06-2011 09:15 PM
I am also interested in this functionality.
I would like the user to be able to download logging files (.txt) from my cRIO target.
Is this possible with HTTP commands via the Web UI builder?
03-07-2011 10:43 AM
If we assume that you have a LabVIEW application running on your cRIO that is exposing some data through web services, there are a couple of possibilities.
You can create a web service call that returns the log data. In order for the browser to treat this as a file, you must set the correct content type in the http header. To do this you can't use the default form of data output. Instead you must create an "httpRequestID" input to your web service VI. With this you can call "Write Response.vi" to give the log data and "Set HTTP Header.vi" to specify the type (text/text probably works for a log). You can look at "examples\comm\webservices\address book\FindContacts.vi" to see an example of calling these 2 VIs. Once you create that web service entry point, you can set that as the URL of the hyperlink control and it should work.
Another option is to have the cRIO application write to a log file that is under the root of the web server running on the machine. (This is the same place the xap for your Web UI Builder application is put.) This file could then be served up through the web server just like any other file.
With either of these solutions there may be concerns about the browser caching results rather than requesting new content each time. There are additional values that can be set in the http headers with the first solution that can help with this, but I think there is still some variation between browsers.
03-07-2011 11:28 AM
I dug a little more and actually created a sample VI. The VI shows returning a dynamic log through a web service and using the "Content-disposition" header to tell the browser to prompt for a location to save. In order to use this approach to return the data, you must configure the VI to the "Stream" output type when adding it as a service VI in your build spec.
03-07-2011 12:20 PM
Any chance that solution can be extended to reading/writing files on the machine running the WebUI code? In other words, provide the equivalent of a read/write function to access files on the machine on which the WebUI code runs? I understand that there are built-in browser safety features that make this a big no-no, but we are not talking about writing Trojans or Viruses here...
03-07-2011 05:23 PM
We could do some limited file support. It just didn't make the cut. Because of the limits of Silverlight security, the user would have to be prompted for the file each time. You can't even programmatically provide a suggested location or file name. So as long as every open is interactive, basic reads and writes can be supported.
03-07-2011 08:27 PM
You can probaby add the following section to the end of the /ni-rt/system/webserver/NISystemWebServer.conf
# Share the files over http
Alias "/files" "./../../.."
Then reboot the target.
That should allow you to use a simple HTTP Get to pull files off the target using a url like http://hostname:3580/files/ni-rt.ini. Just note that you won't be able to browse directories, but if you know the path you should be able to pull off the data files. You can also limit the scope to which files are shared by changing the directory path. The one specified above opens everything up.