Sending images using Http Post

前端 未结 5 1155
轮回少年
轮回少年 2020-11-22 05:52

I want to send an image from the android client to the Django server using Http Post. The image is chosen from the gallery. At present, I am using list value name Pairs to s

5条回答
  •  醉酒成梦
    2020-11-22 06:32

    I usually do this in the thread handling the json response:

    try {
      Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    

    If you need to do transformations on the image, you'll want to create a Drawable instead of a Bitmap.

提交回复
热议问题