Retrofit upload image, FileNotFoundException, Content type uri
<p>Trying to upload image as file using Retrofit, have uploaded files when path was of type <code>file://</code> but now due to naugat , have changed the path Uri to <code>Content:/</code> type, now when i convert this path to file and make retrofit Call, it gives <code>FileNotFoundException</code>    </p>

<pre><code>RequestBody requestFile =
                RequestBody.create(MediaType.parse("multipart/form-data"),photoFile);
</code></pre>

<p>this is the value of <code>photoFile</code> used above- <code>file:/storage/emulated/0/Android/data/com.Bawa.Sketches/files/Pictures/JPEG_20161114_063716_-1561886067.jpg</code></p>

<p>USed <code>setPic()</code> method given in developer's site</p>

<pre><code>   private void setPic(ImageView sketchIv) {
    InputStream input = null;
    try {
        input = getContentResolver().openInputStream(Uri.parse(mCurrentPhotoPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    // Get the dimensions of the View
    int targetW = 300;
    int targetH = 300;

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(input, null, bmOptions);
    try {
        input.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;
    try {
        input = getContentResolver().openInputStream(Uri.parse(mCurrentPhotoPath));

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Bitmap bitmap = BitmapFactory.decodeStream(input, null, bmOptions);
    sketchIv.setImageBitmap(bitmap);
    compressImage(bitmap);
    //showAlertDialog(bitmap);

}
</code></pre>

<p>called <code>CompressImage()</code> method to reduce size of the image and got the <code>photoFile</code> value in the method</p>

<pre><code> private void compressImage(Bitmap lbitmap) {

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
    File f = new File(Uri.parse(mCurrentPhotoPath).toString());
    try {
        f.createNewFile();


        Bitmap bitmap = lbitmap;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 20, bos);
        byte[] bitmapdata = bos.toByteArray();

        FileOutputStream fos = null;

        fos = new FileOutputStream(f);
        fos.write(bitmapdata);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {

    }

    photoFile = f;
    Log.i("response","FILE : "+ f);

}
</code></pre>

<p>P.S. have read Commonsware's answer most of the places - <code>If you get a content:// Uri, please consume it using a ContentResolver and methods like openInputStream() and openOutputStream().</code><br>
do not have any idea how to implement this.</p>