I am developing a web service which is for file uploading. As this service takes only string in its argument which is the absolute path of file. Then using java Stream classes i can write into my destination directory. But how this web service will be accessible for clients. How clients will use it. Any suggestions here after what should i do.
I am mentioning this code here
@Path("/file")
public class FileUploadService
{
static String fileDestination = "/home/user/mywebservice/uploads/";
@POST
@Path("/upload")
public void fileUpload(String fileSource)throws Exception
{
java.nio.file.Path p = Paths.get(fileSource);
String s1=fileDestination+p.getFileName();
FileInputStream fin = new FileInputStream(new File(fileSource));
FileOutputStream fout = new FileOutputStream(new File(s1));
int read = 0;
byte[] bytes = new byte[1024];
fout = new FileOutputStream(new File(s1));
while ((read = fin.read(bytes)) != -1)
{
fout.write(bytes, 0, read);
}
fout.flush();
fout.close();
System.out.println("File uploaded to "+ s1);
}
}
If this is supposed to be a web service. I guess you ought to provide a web interface for users to use your service (in which case you should probably consider using another language to create the logic, perhaps?). Otherwise you can create a Jar file of your complete program and provide the command line interface ie so people can run your program like:
java -jar <jar_file_name> <path_of_src_file>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.