首页 > 解决方案 > 如何从文件uri中提取文件名

问题描述

我制作了一个应用程序来将文件上传到firebase存储并将其设置为firebase. 一切正常,但是当我上传文件时,文件上传firebase成功,但它重命名为唯一名称(对于System.currentTimeMillis()),我如何保留其原始名称?(我试过getLastPathSegment().replaceFirst("[.][^.]+$",""))但它没有用。

    private void uploadFile(Uri pdfUri)
        {
            //uploading progress dialog
            progressDialog = new ProgressDialog(this);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setTitle("Uploading file...");
            progressDialog.setProgress(0);
            progressDialog.show();


          final String fileName = System.currentTimeMillis() + ".pdf"; //TODO use System.currentTimeMillis() if you want a unique name
           final String fileName1 = System.currentTimeMillis() + "";


            StorageReference storageReference = storage.getReference(); //returns parent path

            

标签: androidfilefilenames

解决方案


推荐阅读