2014-06-05 34 views
0

我从我的Android客户端发送图像到java泽西宁静的服务,我成功地做到了这一点。但我的问题是,当我试图发送大于1MB的大图像,它消耗更多的时间,所以我喜欢在CHUNKS发送图像谁能帮我做this.How在CHUNKS发送(POST)图像流服务器使用发送大块图像

+0

响应速度,因为是一个非常充足的问题。给我反馈!请享用 – jeorfevre

回答

0

引用:

  • server code & client call
  • server function name

    /*** SERVER SIDE CODE****/ 
    
    @POST 
    @Path("/upload/{attachmentName}") 
    @Consumes(MediaType.APPLICATION_OCTET_STREAM) 
        public void uploadAttachment(
          @PathParam("attachmentName") String attachmentName, 
          @FormParam("input") InputStream attachmentInputStream) {    
        InputStream content = request.getInputStream(); 
    
    // do something better than this 
    OutputStream out = new FileOutputStream("content.txt"); 
    byte[] buffer = new byte[1024]; 
    int len; 
    while ((len = in.read(buffer)) != -1) { 
        // whatever processing you want here 
        out.write(buffer, 0, len); 
    } 
    out.close(); 
    
    return Response.status(201).build(); 
    } 
    
    
         /**********************************************/ 
    
    
    /** 
        CLIENT SIDE CODE 
    **/ 
        // ..... 
        client.setChunkedEncodingSize(1024); 
        WebResource rootResource = client.resource("your-server-base-url"); 
        File file = new File("your-file-path"); 
        InputStream fileInStream = new FileInputStream(file); 
        String contentDisposition = "attachment; filename=\"" + file.getName() + "\""; 
        ClientResponse response = rootResource.path("attachment").path("upload").path("your-file-name") 
          .type(MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", contentDisposition) 
         .post(ClientResponse.class, fileInStream); 
    

你应该在客户端的文件拆分和还原在服务器上的文件的一部分。 之后,您应该将这些文件合并在一起。看看split /merge file on coderanch

享受! :)