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.
<pre><code> String foo = "bar"; </code></pre>