我想设计一个web项目,当用户上传文件到hadoophdfs时,用户可以通过web看到自己的上传状态。有简单的javaapi吗?
有人能帮忙吗?
现在我只知道如何使用api将文件上传到hdfs。
public synchronized static void upload(FileSystem fs, String local,
String remote) {
// Path home = fs.getHomeDirectory();
Path workDir = fs.getWorkingDirectory();
Path dst = new Path(workDir + "/" + remote);
Path src = new Path(local);
try {
fs.copyFromLocalFile(false, true, src, dst);
log.info("upload " + local + " to " + remote + " successed. ");
} catch (Exception e) {
log.error("upload " + local + " to " + remote + " failed :"
+ ExceptionUtils.getFullStackTrace(e));
}
}
1条答案
按热度按时间wgx48brx1#
您可能会发现filestatus类很有用。通过这个类,您可以获得用户可能想要知道的几乎所有必要的信息,比如获取文件的访问时间、文件的修改时间、文件的长度等。
而且,既然您谈论的是一个web应用程序,我建议您看看webhdfsrestapi。它允许您提交一个get-http请求,该请求将发送一个filestatus json对象作为响应。然后,您可以轻松地使用这个json对象通过web页面向用户呈现状态。
hth公司