上传文件后,与Google Cloud Bucket Storage集成的Android Firebase返回url

时间:2019-09-13 11:10:25

标签: android firebase google-cloud-storage firebase-storage

我已将Firebase存储与Google Cloud Bucket集成在一起。但是,每次尝试获取下载URL时,我都无法获取Google存储URL,而我正在获取Firebase下载URL

下面是代码

   FirebaseStorage storage = FirebaseStorage.getInstance("gs://mybucket");
        StorageReference storageRef = storage.getReference();

        Uri file = Uri.fromFile("path to local file");
        StorageReference riversRef = storageRef.child("images/1234/"+file.getLastPathSegment());

        UploadTask uploadTask = riversRef.putFile(file);
        uploadTask.addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception exception) {
                exception.printStackTrace();
                Log.d(TAG,"File uploaded failed");

                // Handle unsuccessful uploads
            }
        }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                // taskSnapshot.getMetadata() contains file metadata such as size, content-type, etc.
                // ...
                Task<Uri> urlTask = taskSnapshot.getStorage().getDownloadUrl();
                while (!urlTask.isSuccessful());
                Uri downloadUrl = urlTask.getResult();
                Log.d(TAG,"File uploaded succesfull"+downloadUrl);
            }
        });

我无法获取以https://storage.googleapis.com/开头的Google存储网址,而不是我获取的网址为https://firebasestorage.googleapis.com/v0/b

0 个答案:

没有答案