How to Get full File Path of Image and Upload it to server

Hello,
I am following https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/photo-picker/ this link to upload image.
I am able to select and display it.
but i want it full path so that i can copy it to the local place and then upload it to server.

Best Answer

Answers

  • Thanks @KellyHuss for your help.
    It is working fine.
    :smile:

  • sivabhavanisivabhavani USMember ✭✭

    Hi,
    For me it is not working ..can you please help out.

    this is my manifest file

  • FahadAliQureshiFahadAliQureshi Member ✭✭

    @sivabhavani said:
    Hi,
    For me it is not working ..can you please help out.

    this is my manifest file

    This is the permission fault. You have to Check and Request Permissions dynamically at runtime. For this, use the James montemagno's permission plugin. link also given below:

    https://github.com/jamesmontemagno/PermissionsPlugin plugin

    https://github.com/jamesmontemagno/PermissionsPlugin

  • Franck_SDEAFranck_SDEA Member ✭✭
    edited January 31

    @KellyHuss : Two years later... :D

    I use your Android Implementation for pick a picture. If I pick a picture from the "Recents" category, thats work fine but, if I pick an image from the one of theses category (see screenshot), it crash !

    In Visual Studio the error is:

    Unhandled Exception:

    Java.Lang.IllegalArgumentException: Invalid URI: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F90/ORIGINAL/NONE/image%2Fjpeg/866182473

  • Franck_SDEAFranck_SDEA Member ✭✭

    I have found a solution, I post here for others...

    private string GetPathToImage(Android.Net.Uri uri)
    {
        string doc_id = "";
        using (var c1 = ContentResolver.Query(uri, null, null, null, null))
        {
            c1.MoveToFirst();
            string document_id = c1.GetString(0);
            doc_id = document_id.Substring(document_id.LastIndexOf(":") + 1);
        }
    
        string path = null;
    
        // The projection contains the columns we want to return in our query.
        string selection = Android.Provider.MediaStore.Images.Media.InterfaceConsts.Id + " =? ";
        using (var cursor = ContentResolver.Query(Android.Provider.MediaStore.Images.Media.ExternalContentUri, null, selection, new string[] { doc_id }, null))
        {
            if (cursor == null) return path;
            var columnIndex = cursor.GetColumnIndexOrThrow(Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data);
            cursor.MoveToFirst();
            path = cursor.GetString(columnIndex);
        }
        return path;
    }
    
Sign In or Register to comment.