File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Binary Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Binary Files" Watch "Binary Files" New topic
Author

Binary Files

Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
Here is the deal. I have this program that takes a file path and uploads a file into Documentum Server. This works fine when the file is on the server that my application is running on. However, the problem is, that they cannot pass me the file path because the files that are being uploaded are coming from the client's computer, not the server. So, if the application reads a file path, it is going to look on the server machine for the path specified.

The solution is to have the servlet pass me a binary file, and then upload the binary file. Here is where my question lies.

If they create a binary of type File, and then pass me the File object, can I use the getAbsolutePath() method of the File object or is this going to give me the same problem. Will it look for that path on the server, or with the absolutePath point to the actual Binary File.

I appologize in advance if that question is too vague. Let me know what else you are going to need to answer it.

Thanks


Teaching yourself anything is always the cheapest way, but it definitely takes a lot of time and effort.<br /> <br />Thank you javaranch <a href="http://"http://faq.javaranch.com/view?HowToAskQuestionsOnJavaRanch"" target="_blank" rel="nofollow">Learn How to Ask Your Question</a> and be nice
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
getAbsolutePath() returns the absolute path of the file irrespective of the type of the file.Be it binary or text.


Rahul Bhattacharjee
LinkedIn - Blog
Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

To make sure of the basics:
1.) Basically what you are trying to do is transfer a file on a (remote) client machine into a server machine?
2.) The server machine is, at least, a servlet server and maybe a full app server?
3.) Here I'm kinda vague ... the client is a browser? or a fat Java client? I'm guessing a browser...

Some possible solutions...
If client is a browser (I think this is what you want):
1.) Use file upload from the browser (see http://servlets.com/cos/ for servlet classes that handle the file) Use HTML <input type="file"/> on the browser page. Get clever and you may be able to stream directly to the destination application.

If the client is a fat client:
the list here can get huge, these are just a couple of ideas:
1.) open a socket and stream it (not really recommended if you have an app server)
2.) use apache commons http client and send it HTTP (that way a server can reasonably deal with it).

If the client is a browser or a fat client:
1.) Assuming either Windows boxes or Samba on Linux, use CIFS and remotely open the file, given the path through some other mechanism. Note that this has security implications, as in the server needs file access to the client machine. For this reason, this is not recommended. Google "jcifs" though for more info.

Passing an instance of File will not allow you to open a file on a remote machine.
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
Let me ask a question about the first response and answer the second one. Will the get absolute path give me a path that points to the client's machine, or will it take that path and still look on the application server?

Yes, it is a browser, and I don't need to open the file, I just need it to be saved in another program. Basically I need it to work somewhat like when you pass a binary into a database.

I think I'm going to have to try the servlet that you gave me as an example and try to find a way to handle the binary. I'm not sure that the program that my application access will take a binary (but I'm assuming it doesn, even though we all know what happens when you assume). Right now, I'm only able to take a file path.

Can someone point me in the direction to learn more about creating binary and handling binary files?

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Will the get absolute path give me a path that points to the client's machine, or will it take that path and still look on the application server?


It will "take that path and still look on the application server". The only way it will work is if you are on the same machine, or if you "mounted" the shared drives on the client in the same fashion as on the server.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
That's what I thought
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'm guessing the multi-part parser linked before was a rather unimaginative translation from C or something, not showing what I'd call object oriented thinking. If you can use it without looking at it, it might do fine. Knowing where hamburger comes from makes some people vegans.

I implemented my own multipart uploader and (for reasons I can't seem to recall right now) wrote the file to a temp name and folder from File.getTempFile() and then renamed it to a location I liked. I don't recall seeing the full path on the client end in the headers, but if it was there I ignored it.

Look at other multipart handlers. The Fitnesse Wiki may well do it in the fewest possible lines of code. Reading it is an education, and could make you a beef eater again.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Binary Files