我從我的Android客戶端發送圖像到java澤西寧靜的服務,我成功地做到了這一點。但我的問題是,當我試圖發送大於1MB的大圖像,它消耗更多的時間,所以我喜歡在CHUNKS發送圖像誰能幫我做this.How在CHUNKS發送(POST)圖像流服務器使用發送大塊圖像
Q
發送大塊圖像
0
A
回答
0
引用:
- server code & client call
-
/*** 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
享受! :)
0
另一種途徑是可用的,如果你不想太多考慮使用代碼: file upload apache這太棒了! :)
相關問題
- 1. 發送圖像onclick放大活動
- 2. 向GPU發送大圖像時間
- 3. 發送圖像
- 4. 發送圖像
- 5. 發送圖像
- 6. 建議用C塊發送塊大小?
- 7. 發送圖像OutputStream
- 8. 發送圖像ObjectOutputStream
- 9. 發送圖像塊數組時發生額外的錯誤?
- 10. Android圖像發送意圖
- 11. CIFilter inputIntensity滑塊大圖像
- 12. 發送縮略圖圖像到另一個視圖的大圖像查看
- 13. 管道通知 - 發送大塊
- 14. 使用Web服務發送大對象(例如圖像位圖)
- 15. 通過AJAX發送圖像
- 16. 發送圖像與JAVAMAIL
- 17. XMLHttpRequest發送圖像文件
- 18. UWP發送圖像到Whatsapp
- 19. CURL PHP發送圖像
- 20. 發送圖像PHP迅速
- 21. 如何發送圖像AS3
- 22. Sendbird發送圖像文件
- 23. 使用POST發送圖像
- 24. 用於發送圖像
- 25. 發送圖像問題POST
- 26. 在actionscript3中發送圖像
- 27. 發送圖像附件
- 28. 從SDcard發送圖像?
- 29. Java圖像發送網絡
- 30. 通過goRPC發送圖像
響應速度,因爲是一個非常充足的問題。給我反饋!請享用 – jeorfevre