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.

You may also like:
Leave a comment
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.
Did you ever found a good solution for this? What method did you choose. Please share
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.
Can you send your code for me? Because, I’m coding on this issue. thank you very much !
Thanks for your comments. I can not find the code now. If you use netbeans environment, it is pretty quick to build a prototype.
Can you send your code for me? Because, I’m coding on this issue. thank you very much .