浏览文件夹并上传文件firebase

时间:2018-12-08 02:34:42

标签: android android-studio

我试图允许用户浏览视频并将其上传到Firebase存储,但是查看提供的示例,我不确定如何从指定文件转换为允许用户选择。提供的示例是:

Uri file = Uri.fromFile(new File("path/to/images/rivers.jpg"));
StorageReference riversRef = storageRef.child("images/"+file.getLastPathSegment());
uploadTask = riversRef.putFile(file);

我使用ACTION_GET_CONTENT为用户打开文件浏览器,但是如何获取文件路径并替换第一行?

1 个答案:

答案 0 :(得分:0)

File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), YOUR_DIR_NAME);

 if (!dir.exists()) {
        dir.mkdir();
        Log.d(LOG_TAG, "dir not exists and created first time");
    } else {
        Log.d(LOG_TAG, "dir exists");
 }

String absPath = dir.getAbsoultePath();

Uri file = Uri.fromFile(new File(absPath + "rivers.jpg"));