1

How do I upload files in a REST web service? The Java Swing application will call REST web service to use the upload method.

I used apache.commons.fileupload but it is for web-based applications.

How do I download files? I used FileReader and PrintWriter. it is ok for other files, but I have a problem with pictures and zip files. What lib do I need to use to download binary files, pictures, zip, HTML, etc.?

sudo
  • 1,525
  • 7
  • 34
  • 59
  • See the [Basic I/O](http://download.oracle.com/javase/tutorial/essential/io/) lesson of the Java Tutorial for most answers on how to download a resource from a server. – Andrew Thompson Apr 18 '11 at 07:35
  • hi andrew, i am not a little understand what you mean "how to do this form command line and 98% of the way how to do using Swing"? It's impossible to implement? Coz I am doing cloud storage and my supervisor ask me to do web service for swing – sudo Apr 18 '11 at 07:44
  • 1
    "It's impossible to implement?" No, I did not mean that at all! I just meant that if it worked from the command line, it would then be easy to add the 'with Swing' functionality. A `JButton` with an `ActionListener` attached, creating a `JFileChooser`, and if the user selects a `File` for upload, creating a `SwingWorker` that updates a `JProgressBar` - and it is done. ...OK, maybe the job is **80%** done. And BTW - 99% of statistics are made up on the spur of the moment. ;) But either way - try to separate the file upload/download from the Swing aspect. They are largely different qns. – Andrew Thompson Apr 18 '11 at 07:59
  • BTW, do you know which lib file need to used to upload? – sudo Apr 18 '11 at 08:02
  • 1
    I am not experienced with server side development, so cannot comment on that aspect. For the client side part of a file upload, it is also largely covered in the Basic I/O lesson. Thinking about it, I recommend you edit your question to remove the mention of Swing and just reduce it to 'server side file upload'. Ask other more specific questions on separate threads. – Andrew Thompson Apr 18 '11 at 08:16
  • 1
    When you do get it working on its own and integrate the solution into your Swing GUI, make sure you do these long running operations outside the gui thread. http://download.oracle.com/javase/tutorial/uiswing/concurrency/worker.html – Jim Jul 15 '11 at 17:23

1 Answers1

0

https://stackoverflow.com/a/32253028/15789

For anyone who stumbles upon this page - the above may help. It is an example REST service that receives bytes of a file and sends zipped bytes in response. Using JAX-RS Client to send request and receive response.

Community
  • 1
  • 1
RuntimeException
  • 1,593
  • 2
  • 22
  • 31