いつもお世話になります。
表記の通り、
サーバ(サーブレット)からクライント(Android アプリ)側に画像データを送る方法を教えてください。
下記のソースのように文字列は送れるけど、画像ってどういう考えで送れば良いのか思い当たらないです
バイナリで送って-->クライアント側で変換する?とか
もっと簡単な方法とかあるの?
java
1//サーバ側 2public class Hello extends HttpServlet{ 3 4 public void doGet ( HttpServletRequest request, HttpServletResponse response ) 5 throws ServletException, IOException { 6 7 response.setContentType("image/jpeg; charset=UTF-8"); 8 PrintWriter out = response.getWriter(); 9 out.println("Hello Servlet!"); //文字列は送れる 10 out.println(**.jpeg); //<--------このような感じ? 11 12 } 13}
以下のように変えましたがうまくいかず。意味不明。
画像のファイル1.jpgは同じ位置にあります。
java
1public void doGet( 2 HttpServletRequest request, 3 HttpServletResponse response 4) throws ServletException, IOException { 5 response.setContentType("application/octet-stream"); 6 response.setHeader("Content-Disposition" , 7 "attachment; filename='1.jpg");//変更 8 9 OutputStream out = response.getOutputStream(); 10 11 // ここをファイルからbyte[] を取り出してください。 12 byte[] downloadData = "1.jpg".getBytes(); //変更 これだとスマホ側に1.jpgのまま出るだけ 13 out.write(downloadData); 14 out.close(); 15}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/22 14:31
退会済みユーザー
2018/02/22 14:38
退会済みユーザー
2018/02/22 14:43
2018/02/22 15:01
2018/02/23 02:39
2018/02/23 05:46
2018/02/23 06:38
2018/02/24 05:34