Reputation: 45
I am working on an application in which I need to open attachments. I need to click on the "Open" button and open a pdf file. The way I do it, is by getting the content from the Server and writing it to a location on the temp directory.
However when I try to access this service from a remote machine, http://myserverIP:port/openMyAttachment, it accesses the temp directory of myserverIP instead of the local machine. It then opens the file on myserverIP.
I am using the following code to get the temp directory:
String tmp = System.getProperty("java.io.tmpdir");
JFileChooser fc = new JFileChooser();
FileSystemView fsv = fc.getFileSystemView();
File f = fsv.getDefaultDirectory();
String dir = f.getAbsolutePath();
String strDirectory = "temp~" + f.separator;
Can someone please share your thoughts? How can I get to access the temp directory on teh local machine and write the file to the local machine?
Upvotes: 0
Views: 2628
Reputation: 5591
You're trying to do too much on the server. If you have a Java program running locally, then it should be showing the JFileChooser
, then fetching the file, writing it to a local temp space, and displaying it. The only thing the server should do is provide an InputStream
to get the file contents from. If you change your server to have a getAttachment
query (or something) instead of the openMyAttachment
query that just serves back a pdf file. Then you should be able to fetch it with a URLConnection
and complete the work on the local computer.
Upvotes: 1