0

I want to upload image to server using Retrofit. I'm Getting my Image from Camera App & from Gallery.

here you can see my onActivityResult method on Below code Camera image using Bitmap & Gallery image using Uri, is there way to send both type of image in server using Retrofit.

  @Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == TAKE_PICTURE) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        profile.setImageBitmap(photo);
    } else if (requestCode == ACTIVITY_SELECT_IMAGE) {
        Uri imgUri = data.getData();
        profile.setImageURI(imgUri);
    }
}

I don't have idea how to upload image to server please.

  • You can better take a picture in such a way that a file is created and not only a thumbnail bitmap. For the file you can use a FileProvider to have a nice uri. You then have an uri with selecting a file or taking a picture. You then upload to server from uri. – blackapps Feb 12 '22 at 14:42
  • [The following link can be of help to your question](https://stackoverflow.com/questions/39953457/how-to-upload-an-image-file-in-retrofit-2) – Kwesi Welbred May 25 '22 at 09:02

0 Answers0