从firebase获取downloadUrl

时间:2017-06-14 22:53:18

标签: android firebase firebase-storage

我开发了一个代码来将图像上传到firebase。

在咨询消防基地存储时,我发现图像已经很好了。

要检索downloadUrl,我使用了Listener,但在我看来,Listener不起作用。

        mFirebaseStorage = FirebaseStorage.getInstance();
        mFirebaseDatabase = FirebaseDatabase.getInstance();



        mProductStorageReference = mFirebaseStorage.getReference().child("images");
        mPostsDatabaseReference = mFirebaseDatabase.getReference().child("posts");

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                File f = new File(imagePath);
                bitmap = BitmapFactory.decodeFile(f.getPath());
                bitmap.compress(Bitmap.CompressFormat.JPEG, 0, bytes);
                String path = MediaStore.Images.Media.insertImage(PostNewProductActivity.this.getContentResolver(),
                        bitmap, imagePath, null);
                Uri uri = Uri.parse(path);


                // Upload file to Firebase Storage
                final String finalAdress = adress;
                final double finalMyLat = MyLat;
                final double finalMyLong = MyLong;



                StorageReference photoRef = mProductStorageReference.child(uri.getLastPathSegment());
                photoRef.putFile(uri)
                        .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                                Log.i("tag", "onSuccess");

                                // When the image has successfully uploaded, we get its download URL
                                Uri downloadUrl = taskSnapshot.getDownloadUrl();

                                // Set the download URL to the message box, so that the user can send it to the database
                                Product product = new Product(userName, mLastUpdateTime, finalAdress, finalMyLat, finalMyLong,
                                        descriptionUser.getText().toString(), descriptionApi, downloadUrl.toString(), price.getText().toString());
                                mPostsDatabaseReference.push().setValue(product);


                            }
                        }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        // Handle unsuccessful uploads
                        Log.i("tag", "onFailure");
                    }
                });

我查阅了我没有找到-onSuccess tag-和-onFailure标签的日志,尽管照片在火盆中很好

0 个答案:

没有答案