1

我想设计一个web项目,当用户上传文件到hadoop hdfs时,用户可以通过web看到他们的上传状态。有没有简单的java api?

任何人都可以帮忙吗?

现在我只知道方法,如何使用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));
    }
}
4

1 回答 1

0

您可能会发现FileStatus类很有用。通过这个类,你可以获得用户可能想知道的几乎所有必要的信息,比如获取文件的访问时间、文件的修改时间、文件的长度等。

而且,由于您在谈论 Web 应用程序,我建议您查看WebHDFS REST API。它允许您提交一个 GET HTTP 请求,该请求将发送一个FileStatus JSON 对象作为响应。然后,您可以轻松地使用此 JSON 对象通过网页向您的用户呈现状态。

高温高压

于 2013-06-30T19:42:30.493 回答