Firebase存储异常:com.google.firebase.storage.StorageException:该位置不存在对象

时间:2019-01-26 12:31:02

标签: android image firebase storage firebase-storage

我正在尝试将图像上传到Firebase存储中,然后获取下载URL并将其保存在Firebase数据库中。图像已成功上传到Firebase存储中,但是我无法获得已保存图像的下载URL。 task.isSuccessful()始终在返回false  OnCompleteListener()。

    String groupId = UUID.randomUUID().toString();
  BitmapDrawable bitmapDrawable = (BitmapDrawable) mGroupIcon.getDrawable();
       Bitmap bitmap = bitmapDrawable.getBitmap();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        StorageMetadata storageMetadata=new StorageMetadata.Builder().setCustomMetadata("text",".saa").build();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
        byte[] data = baos.toByteArray();
        final UploadTask uploadTask = storageReference.child("GroupId " + groupId).putBytes(data,storageMetadata);
    Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
        @Override
        public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
            if (!task.isSuccessful()) {
                try {
                    Toast.makeText(getApplicationContext(),task.getException().getMessage().toString(),Toast.LENGTH_SHORT).show();
                }catch (Exception e)
                {
                    e.printStackTrace();
                }

                throw task.getException();
            }

            return storageReference.getDownloadUrl();
        }

    }).addOnCompleteListener(new OnCompleteListener<Uri>() {
        @Override
        public void onComplete(@NonNull Task<Uri> task) {

            if (task.isSuccessful()) {
                Uri downloadUri = task.getResult();
                mDownloadUrl = downloadUri.toString();
                String name = mGroupName.getText().toString();
                String desc = mGroupDesc.getText().toString();

                    String currentUserId = user.getUid();
                    GroupModel model = new GroupModel(name, desc, mDownloadUrl, currentUserId, groupId);
                    mDatabaseReference.push().setValue(model);  
            }
            else{
                Toast.makeText(getApplicationContext(),"Error orrured",Toast.LENGTH_SHORT).show();
            }
        }
    });

此处任务总是不成功 当我将它放入try catch而不是if时,它将抛出Object在位置异常处不存在。

这是我总是得到的例外。

com.google.firebase.storage.StorageException: Object does not exist at location.

Here my images are uploaded in the database

0 个答案:

没有答案