我正在开发一个用于文件上传的Web服务。 由于此服务仅在其参数中采用字符串,该参数是文件的绝对路径。 然后使用java Stream类,我可以写入我的目标目录。 但是如何为客户提供此Web服务。 客户将如何使用它。 在我应该做什么之后有任何建议。
我在这里提到这段代码
@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); } }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); } }最满意答案
如果这应该是一个Web服务。 我想你应该为用户提供一个Web界面来使用你的服务(在这种情况下你应该考虑使用另一种语言创建逻辑,也许?)。 否则,您可以创建完整程序的Jar文件并提供命令行界面,即人们可以运行您的程序,如:
java -jar <jar_file_name> <path_of_src_file>
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 i.e. so people can run your program like:
java -jar <jar_file_name> <path_of_src_file>
更多推荐
发布评论