1. Are you ready for the Galaxy S20? Here is everything we know so far!

Getting file path from file browser for firebase upload

Discussion in 'Android Development' started by john barrowman, Dec 8, 2018.

  1. john barrowman

    Thread Starter

    Currently I have a button which opens a file browser for the user to select a file (currently images) but once they've selected it I'm not sure how I can get the file path and use that to upload it to Firebase storage.

    Code (Text):
    1.  
    2. private void fileChooser(){
    3.     Intent intent = new Intent();
    4.     intent.setType("image/*");
    5.     intent.setAction(Intent.ACTION_GET_CONTENT);
    6.     startActivityForResult(Intent.createChooser(intent,"Select a file to upload"),
    7.     REQUEST_CODE);
    8.  
    9. }
    10.  
    11. [USER=1021285]@override[/USER]
    12. protected void onActivityResult(int returnedCode, int returnedResult, Intent file){
    13.     super.onActivityResult(returnedCode, returnedResult, file);
    14.     if(returnedCode == REQUEST_CODE && returnedResult == RESULT_OK && file != null && file.getData() != null){
    15.        
    16.     }
    17. }
    18.  
    what would I put inside the if statement to be able to get the filepath and use UploadTask to upload it?
     


    #1 john barrowman, Dec 8, 2018
    Last edited by a moderator: Dec 8, 2018
  2. Deleted User

    Deleted User Guest

    Specifically, to get the path of the file you chose:

    Code (Text):
    1.  
    2. protected void onActivityResult(int returnedCode, int returnedResult, Intent file){
    3. ..
    4.   Uri uri = file.getData();
    5.   String filePath = uri.getPath();
    6. ..
    7. }
    8.  
     
Loading...
Similar Threads - Getting file path
  1. kausrita
    Replies:
    5
    Views:
    84
  2. Kharl
    Replies:
    4
    Views:
    169
  3. Astha Gupta
    Replies:
    0
    Views:
    127
  4. James Mountain
    Replies:
    0
    Views:
    535
  5. albanian_5
    Replies:
    1
    Views:
    3,193
  6. svim
    Replies:
    1
    Views:
    866
  7. LefmyHans
    Replies:
    2
    Views:
    304
  8. Emre Can AYDIN
    Replies:
    4
    Views:
    974
  9. NathanaelEy
    Replies:
    0
    Views:
    342
  10. Quadra1
    Replies:
    5
    Views:
    984

Share This Page

Loading...