0

您好我正在尝试使用weed-fs java 客户端将文件上传到 weed-fs 。我想我已经按照如何安装 weed 的说明成功安装了 weed。总之我

  1. 用命令启动master$./weed master
  2. 然后$./weed volume -port=9444我的应用服务器的卷服务器已经占用了 8080 端口
  3. 通过使用命令 `$./weed upload -dir="any_dir_with_small_files" 上传文件夹来测试一切是否正常

至此,一切都很好。在我的应用程序中,我尝试multipart/form-data从浏览器发布,该浏览器被调用一个类来处理上传的 servlet 拦截。

    public void upload(HttpServletRequest request) throws FileUploadException, IOException {
    client = new WeedFSClient(MASTER_ADDRESS, MASTER_PORT);
    if (ServletFileUpload.isMultipartContent(request)) {
        FileItemIterator fileItemIterator = new ServletFileUpload().getItemIterator(request);
        InputStream inputStream = null;
        while (fileItemIterator.hasNext()) {
            FileItemStream item = fileItemIterator.next();
            if (!item.isFormField()) {
                inputStream = item.openStream();
                File file = new File(request.getServletContext().getRealPath("/")+"img/uploads/"+item.getName());
                FileOutputStream fos = new FileOutputStream(file);
                Streams.copy(inputStream, fos, true);
                RequestResult result = client.upload(file);
                if (result.isSuccess()) {
                    System.out.println("uploaded file with ID "+result.getFid());
                }
            }
        }
    }
}

当我运行它时,我会得到很多调试信息

    Info:   DEBUG - Get connection for route {}->http://localhost:9444
Info:   DEBUG - Connecting to localhost:9444
Info:   DEBUG - CookieSpec selected: best-match
Info:   DEBUG - Auth cache not set in the context
Info:   DEBUG - Target auth state: UNCHALLENGED
Info:   DEBUG - Proxy auth state: UNCHALLENGED
Info:   DEBUG - Attempt 1 to execute request
Info:   DEBUG - Sending request: POST /2,ace132597a HTTP/1.1
Info:   DEBUG - >> "POST /2,ace132597a HTTP/1.1[\r][\n]"
Info:   DEBUG - >> "Transfer-Encoding: chunked[\r][\n]"
Info:   DEBUG - >> "Content-Type: multipart/form-data; boundary=TVf_3Jwe1DSTTHoUnZcyiA5KCVUFixPeItY3[\r][\n]"
Info:   DEBUG - >> "Host: localhost:9444[\r][\n]"
Info:   DEBUG - >> "Connection: Keep-Alive[\r][\n]"
Info:   DEBUG - >> "User-Agent: Apache-HttpClient/4.2.5 (java 1.5)[\r][\n]"
Info:   DEBUG - >> "[\r][\n]"
Info:   DEBUG - >> POST /2,ace132597a HTTP/1.1
Info:   DEBUG - >> Transfer-Encoding: chunked
Info:   DEBUG - >> Content-Type: multipart/form-data; boundary=TVf_3Jwe1DSTTHoUnZcyiA5KCVUFixPeItY3
Info:   DEBUG - >> Host: localhost:9444
Info:   DEBUG - >> Connection: Keep-Alive
Info:   DEBUG - >> User-Agent: Apache-HttpClient/4.2.5 (java 1.5)
Info:   DEBUG - >> "1088[\r][\n]"
Info:   DEBUG - >> "--TVf_3Jwe1DSTTHoUnZcyiA5KCVUFixPeItY3[\r][\n]"
Info:   DEBUG - >> "Content-Disposition: form-data; name="fileBody"; filename="23.jpg"[\r][\n]"
Info:   DEBUG - >> "Content-Type: text/plain[\r][\n]"
Info:   DEBUG - >> "[\r][\n]"
Info:   DEBUG - >> "[0xff][0xd8][0xff][0xe0][0x0][0x10]JFIF[0x0][0x1][0x1][0x1][0x0]H[0x0]H[0x0][0x0][0xff][0xe1][0x16][0xf2]Exif[0x0][0x0]II*[0x0][0x8][0x0][0x0][0x0][0x17][0x0][0x0][0x1][0x3][0x0][0x1][0x0][0x0][0x0][0x90][0x6][0x0][0x0][0x1][0x1][0x3][0x0][0x1][0x0][0x0][0x0][0x1a][0x4][0x0][0x0][0x2][0x1][0x3][0x0][0x3][0x0][0x0][0x0]"[0x1][0x0][0x0][0x6][0x1][0x3][0x0][0x1][0x0][0x0][0x0][0x2][0x0][0x0][0x0][0xf][0x1][0x2][0x0][0x6][0x0][0x0][0x0]([0x1][0x0][0x0][0x10][0x1][0x2][0x0][0x15][0x0][0x0][0x0].[0x1][0x0][0x0][0x12][0x1][0x3][0x0][0x1][0x0][0x0][0x0][0x1][0x0][0x0][0x0][0x15][0x1][0x3][0x0][0x1][0x0][0x0][0x0][0x3][0x0][0x0][0x0][0x1a][0x1][0x5][0x0][0x1][0x0][0x0][0x0]D[0x1][0x0][0x0][0x1a][0x1][0x5][0x0][0x1][0x0][0x0][0x0]L[0x1][0x0][0x0][0x1b][0x1][0x5]

就像 x10 一样,我的屏幕高度会这样继续,不要忘记我设置了一个非常小的字体大小。有人可以告诉我这应该怎么做。如果您能指导我正确地指导杂草 fs 的 java 客户端,我也将不胜感激。提前致谢。

4

1 回答 1

0

看来你做得对。如果您不想看到它们,只需关闭调试消息即可。

于 2014-10-27T21:36:54.430 回答