firebase url在firebase中保存了错误的URL地址

时间:2018-10-25 10:14:23

标签: java android firebase firebase-realtime-database

storageReference.child("uploads").child(id).child(filename).putFile(data)
                .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                        String url = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();
                        //store the data to real time DB
                        DatabaseReference reference = database.getReference();
                        final String pdfname = name.getText().toString();
                        final String  qeditname=name.getText().toString();
                       // reference.child("PDF").child(id).child(filename1+"name").setValue(pdfname);
                        reference.child("PDF").child(id).child(filename1+qeditname).setValue(url).addOnCompleteListener(new OnCompleteListener<Void>() {
                            @Override
                            public void onComplete(@NonNull Task<Void> task) {
                                if (task.isSuccessful()) {
                                   progressDialog.dismiss();
                                    Toast.makeText(Upload.this, "Upload succesfully", Toast.LENGTH_LONG).show();
                                } else {
                                    Toast.makeText(Upload.this, "Error", Toast.LENGTH_LONG).show();
                                }
                            }
                        });

database

这是我的代码...

中的问题是什么

String url = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();

这里的网址保存为“ com.google.android.gms.tasks.zzu@41c431b8”,这是错误的,我想保存为 “ https://firebasestorage.googleapis.com .....................”

1 个答案:

答案 0 :(得分:0)

将代码更改为此

getResult().getStorage().getDownloadUrl().toString()