Question: I'm trying to get image from gallery. 

```
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select picture"), resultCode );

```

After I returned from this activity I have a data, which contains Uri. It looks like:

```
content://media/external/images/1

```

How can I convert this path to real one (just like '`/sdcard/image.png`') ?

Thanks

Answer: 
One easy and best method copy file to the real path and then get their path I checked it 10 devices on **android API-16 to API-30** working fine.

```
@Nullable
public static String createCopyAndReturnRealPath(
       @NonNull Context context, @NonNull Uri uri) {
    final ContentResolver contentResolver = context.getContentResolver();
    if (contentResolver == null)
        return null;

    // Create file path inside app's data dir
    String filePath = context.getApplicationInfo().dataDir + File.separator + "temp_file";
    File file = new File(filePath);
    try {
        InputStream inputStream = contentResolver.openInputStream(uri);
        if (inputStream == null)
            return null;
        OutputStream outputStream = new FileOutputStream(file);
        byte[] buf = new byte[1024];
        int len;
        while ((len = inputStream.read(buf)) > 0)
            outputStream.write(buf, 0, len);
        outputStream.close();
        inputStream.close();
    } catch (IOException ignore) {
        return null;
    }
    return file.getAbsolutePath();
}

```
This helped me to get uri from Gallery and convert to a file for Multipart upload

```
File file = FileUtils.getFile(this, fileUri);

```

<https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java>