Firebase异常:对象不存在

问题描述 投票:0回答:1

我正在将图像上传到Firebase存储,并且此错误不断出现

E / StorageException:发生StorageException。对象在该位置不存在。代码:-13010 HttpResult:404 E / StorageException:{“错误”:{“代码”:404,“消息”:“未找到。无法获取对象”,“状态”:“ GET_OBJECT”}}java.io.IOException:{“错误”:{“代码”:404,“消息”:“未找到。无法获取对象”,“状态”:“ GET_OBJECT”}}]

这是我的代码:

StorageReference postimage_path=firebaseStorage.child("Post Image").child(random+".jpg");

postimage_path.putFile(newposturi);
postimage_path.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
    @Override
    public void onComplete(@NonNull Task<Uri> task) {
        if(task.isSuccessful())
        {

            Uri download_url=task.getResult();
            Map<String,String> postmap=new HashMap<>();
            postmap.put("download url",download_url.toString());
            postmap.put("Description",post);
            postmap.put("user_id",currentuser);
            postmap.put("timestamp",""+FieldValue.serverTimestamp());
            postfirestore.collection("Posts").add(postmap).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
                @Override
                public void onComplete(@NonNull Task<DocumentReference> task) {
                    if(task.isSuccessful()){
                        Toast.makeText(PostActivity.this, "Post Successful", Toast.LENGTH_SHORT).show();
                        Intent intent=new Intent(PostActivity.this,MainActivity.class);
                        startActivity(intent);
                        finish();
                    }

                    else{
                    String error=task.getException().getMessage();
                    Toast.makeText(PostActivity.this, "Error while Posting :"+error, Toast.LENGTH_SHORT).show();}
                    newpostprogress.setVisibility(View.INVISIBLE);
                }
            });
        }

android firebase google-cloud-storage firebase-storage
1个回答
0
投票

错误消息告诉您,存储的对象中没有这样构建的路径:

StorageReference postimage_path=firebaseStorage.child("Post Image").child(random+".jpg");

缺少的对象导致getDownloadUrl()失败。

您必须进行一些调试才能弄清楚路径应该是什么,并确保命名对象确实存在。

© www.soinside.com 2019 - 2024. All rights reserved.