Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Firebase存储错误试图将数据插入我的数据库_Java_Android_Firebase_Firebase Storage - Fatal编程技术网

Java Firebase存储错误试图将数据插入我的数据库

Java Firebase存储错误试图将数据插入我的数据库,java,android,firebase,firebase-storage,Java,Android,Firebase,Firebase Storage,我一直在四处寻找一些问题,但无法找到我做错了什么 我正在尝试将一个文件上载到Firebase存储,然后将下载URL写入数据库中的一个节点中 现在,这是一件奇怪的事情,我正在与电子邮件和密码提供商进行身份验证,但奇怪的是,代码将我的图像上传到存储中,但不断循环以将下载链接放置在我的数据库中,然后只给我以下错误: E/StorageException:发生了StorageException。 用户没有访问此对象的权限 现在,我已经检查了我的规则,因为我已经通过了认证,所以我尝试了这两个,但没有成功

我一直在四处寻找一些问题,但无法找到我做错了什么

我正在尝试将一个文件上载到Firebase存储,然后将下载URL写入数据库中的一个节点中

现在,这是一件奇怪的事情,我正在与电子邮件和密码提供商进行身份验证,但奇怪的是,代码将我的图像上传到存储中,但不断循环以将下载链接放置在我的数据库中,然后只给我以下错误:

E/StorageException:发生了StorageException。 用户没有访问此对象的权限

现在,我已经检查了我的规则,因为我已经通过了认证,所以我尝试了这两个,但没有成功

service firebase.storage {
  match /b/my-bucket.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}
这个呢

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}
现在我也试过了

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}
还是有同样的问题

这是我用来将文件上传到存储器并将下载的URL放入数据库的代码

 public void cargarProductoFirebase(final String nombreProducto, final float precioProducto, final Dialog dialog, final ProgressDialog progressDialog, Uri filePath) {

        mStorageReference.child("fotos").child(mAuth.getCurrentUser().getUid()).child(filePath.getLastPathSegment()).putFile(filePath).continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
            @Override
            public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                if (!task.isSuccessful()) {
                    throw task.getException();
                }
                return mStorageReference.getDownloadUrl();
            }
        }).addOnCompleteListener(new OnCompleteListener<Uri>() {
            @Override
            public void onComplete(@NonNull Task<Uri> task) {
                if (task.isSuccessful()) {
                    Uri downloadUri = task.getResult();
                    Map<String, Object> producto = new HashMap<>();
                    producto.put("nombreProducto", nombreProducto);
                    producto.put("precioProducto", precioProducto);
                    producto.put("imagen",downloadUri.toString());
                    mDatabase.child("Usuarios").child(mAuth.getCurrentUser().getUid()).child("productos").push().updateChildren(producto).addOnCompleteListener(new OnCompleteListener<Void>() {
                        @Override
                        public void onComplete(@NonNull Task<Void> task) {

                            dialog.dismiss();
                            progressDialog.dismiss();
                            Toast.makeText(mContext, "Se cargo el producto correctamente.", Toast.LENGTH_SHORT).show();

                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            progressDialog.dismiss();
                            Toast.makeText(mContext, "Error al cargar el producto" + e.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    });

                } else {
                    Toast.makeText(mContext, "upload failed: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
public void cargarProductoFirebase(最终字符串nombreProducto、最终浮点precioProducto、最终对话框、最终进度对话框ProgressDialog、Uri文件路径){
mStorageReference.child(“fotos”).child(mAuth.getCurrentUser().getUid()).child(filePath.getLastPathSegment()).putFile(filePath).continueWithTask(新Continuation()){
@凌驾
公共任务(@NonNull Task Task)引发异常{
如果(!task.issusccessful()){
抛出task.getException();
}
返回mStorageReference.getDownloadUrl();
}
}).addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
Uri downloadUri=task.getResult();
Map producto=newhashmap();
producto.put(“nombreProducto”,nombreProducto);
产品投入(“precioProducto”,precioProducto);
producto.put(“imagen”,downloadUri.toString());
mDatabase.child(“Usuarios”).child(mAuth.getCurrentUser().getUid()).child(“productos”).push().updateChildren(producto).addOnCompleteListener(新OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
dialog.dismise();
progressDialog.disclose();
Toast.makeText(mContext,“Se cargo el producto correctamente.”,Toast.LENGTH_SHORT.show();
}
}).addOnFailureListener(新的OnFailureListener(){
@凌驾
public void onFailure(@NonNull异常e){
progressDialog.disclose();
Toast.makeText(mContext,“Error al-cargar el producto”+e.getMessage(),Toast.LENGTH_SHORT.show();
}
});
}否则{
Toast.makeText(mContext,“上载失败:”+task.getException().getMessage(),Toast.LENGTH_SHORT.show();
}
}
});
}
错误跟踪

2018-10-09 20:32:49.442 9767-9821/com.example.macbook.firebasemvp E/StorageException:发生了StorageException。 用户没有访问此对象的权限。 代码:-13021 HttpResult:403 2018-10-09 20:32:49.443 9767-9821/com.example.macbook.firebasemvp E/StorageException:{ “错误”:{“代码”:403,“消息”:“开发人员凭据” 必需。“}} java.io.IOException:{“错误”:{“代码”:403,“消息”:“需要开发人员凭据”。} 在com.google.firebase.storage.obfuscated.zzj.zza(com.google.firebase:firebase存储@@16.0.2:455) 位于com.google.firebase.storage.obfuscated.zzj.zza(com.google.firebase:firebase存储@@16.0.2:3435) 位于com.google.firebase.storage.obfuscated.zzc.zza(com.google.firebase:firebase存储@@16.0.2:65) 在com.google.firebase.storage.obfuscated.zzc.zza(com.google.firebase:firebase存储@@16.0.2:57) 在com.google.firebase.storage.zzc.run(com.google.firebase:firebase存储@@16.0.2:68) 位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 运行(Thread.java:764)

此外,文件已上载到正确的位置,但错误仍然存在,无法将下载的URL放置到数据库中

编辑 我缩小了代码,删除了数据库部分,但仍然存在同样的问题

 public void cargarProductoFirebase(final String nombreProducto, final float precioProducto, final Dialog dialog, final ProgressDialog progressDialog, Uri filePath) {

        mStorageReference.child("fotos").child(mAuth.getCurrentUser().getUid()).child(filePath.getLastPathSegment()).putFile(filePath).continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
            @Override
            public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                if (!task.isSuccessful()) {
                    throw task.getException();
                }
                return mStorageReference.getDownloadUrl();
            }
        }).addOnCompleteListener(new OnCompleteListener<Uri>() {
            @Override
            public void onComplete(@NonNull Task<Uri> task) {
                if (task.isSuccessful()) {
                    Uri downloadUri = task.getResult();
                    Log.e(TAG, "onComplete: Success " );

                } else {
                    Toast.makeText(mContext, "upload failed: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                }
            }
        });
public void cargarProductoFirebase(最终字符串nombreProducto、最终浮点precioProducto、最终对话框、最终进度对话框ProgressDialog、Uri文件路径){
mStorageReference.child(“fotos”).child(mAuth.getCurrentUser().getUid()).child(filePath.getLastPathSegment()).putFile(filePath).continueWithTask(新Continuation()){
@凌驾
公共任务(@NonNull Task Task)引发异常{
如果(!task.issusccessful()){
抛出task.getException();
}
返回mStorageReference.getDownloadUrl();
}
}).addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
Uri downloadUri=task.getResult();
Log.e(标签“onComplete:Success”);
}否则{
Toast.makeText(mContext,“上载失败:”+task.getException().getMessage(),Toast.LENGTH_SHORT.show();
}
}
});
图片:

此外,没有像旧的存储实现那样的
addOnProgressUpdate

问题在于原因
return mStorageReference.getDownloadUrl();
StorageReference fileReference = mStorageReference.child("fotos").child(mAuth.getCurrentUser().getUid()).child(filePath.getLastPathSegment())
fileReference.putFile(filePath).continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
    @Override
    public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
        if (!task.isSuccessful()) {
            throw task.getException();
        }
        return fileReference.getDownloadUrl();
    }
    ...