File Transfer through Java Web Service

I was trying to do a java web service project which allows users to upload files through web service. After searching for several days, I realized that, this is not a good idea. In face, web service can transfer Image from end to end, but not for large regular files, such as pdf, doc, etc. The reason is that server will read file to byte array which consumes much memory. If many users use it at the same time, this may lead to scalability issue.

In fact, if we use web service to download a file,  we may have the following function:

public File getFile(String Name) throws IOException

If you test this code in Java Web Service environment, the return will be a String, not a File object like what we expected. If it is a byte array, it would be easy to define the function's return type and transfer the byte array, like regular arrays. But a file has to be handled in different approach.
To transfer files using Web Service, the correct way should be using FTP to upload file, and after uploading use Web Service to store all related information of the file. I will dig deeper for this topic, finally get a system which centralizes file upload functions for many different systems like the following figures. I may post my code  in my later post, please search and find it.


Category >> Web Services  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";

  1. mansour on 2009-11-18

    that is totally useful topic. Im trying to do exactly the same thing. But we need more details about how to transfer file thro FTP using java webservice.

  2. Rohit on 2010-4-26

    Did you ever found a good solution for this? What method did you choose. Please share

  3. admin on 2010-4-28

    I implement FTP in a PHP system. PHP has an FTP function which can transfer files.
    The point here is to separate the file information with real file transfer. Use Web Service to insert/update file information, use FTP to transfer real file.

  4. Nguyễn Duy Chinh on 2011-10-10

    Can you send your code for me? Because, I’m coding on this issue. thank you very much !

  5. Admin on 2011-10-19

    Thanks for your comments. I can not find the code now. If you use netbeans environment, it is pretty quick to build a prototype.

  6. purnachander on 2012-2-1

    Can you send your code for me? Because, I’m coding on this issue. thank you very much .

Leave a comment