0

I'm using the following code to convert file uri(which is selected from the sdcard/external memory) into path and upload this path to server. while uploading files from internal memory its working perfectly. When I'm trying to select a file from external memory/sdcard to the server I'm getting java.io.fileNotFoundException:/mnt/media_rw/:/open failed: EACCESS(Permission denied).And I have included all the permissions in Manifest file.

 private String getRealPathFromURI(Uri contentURI) {
    String result;
    Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);
    if (cursor == null) { // Source is Dropbox or other similar local file path
        result = contentURI.getPath();
    } else {
        cursor.moveToFirst();
        int idx = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
        result = cursor.getString(idx);
        cursor.close();
    }
    return result;
}
Gowri
  • 21
  • 5
  • "while uploading files from internal memory its working perfectly" -- only in limited scenarios on some devices. See [this](https://stackoverflow.com/questions/49221312/android-get-real-path-of-a-txt-file-selected-from-the-file-explorer), [this](https://stackoverflow.com/questions/35870825/getting-the-absolute-file-path-from-content-uri-for-searched-images), [this](https://stackoverflow.com/questions/48510584/onactivityresults-intent-getpath-doesnt-give-me-the-correct-filename), and [this](https://commonsware.com/blog/2016/03/15/how-consume-content-uri.html). – CommonsWare May 18 '18 at 11:35
  • @CommonsWare Thanks for your reply. I will check it – Gowri May 18 '18 at 11:43
  • `I'm using the following code to upload file` ??? That code does not upload a file at all. – greenapps May 18 '18 at 11:56
  • @greenapps. Sorry convert from Uri to path – Gowri May 18 '18 at 11:59
  • Well edit your post. And tell which paths you get. You will get invalid paths to begin with. You should not even try to get a path from an uri. just use the uri itself. Further you did not tell how you got that uri. – greenapps May 18 '18 at 12:03

0 Answers0