• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Binary Files

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getAbsolutePath() returns the absolute path of the file irrespective of the type of the file.Be it binary or text.
 
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Nicholas Carrier
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I thought
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
this llama doesn't want your drama, he just wants this tiny ad for his mama
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic