我一直在寻找周围的一些问题,但不能得到的,我做错了什么地步。
我想将文件上传到火力地堡储存,然后写在我的数据库节点内的下载网址。
现在,这是奇怪的事情,我与电子邮件地址和密码认证供应商,但奇怪的是,该代码上传我的图像到存储,但仍将继续循环,从而将我的数据库中的下载链接,然后只是给了我这个错误:
发生StorageException:E / 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;
}
}
}
并且仍然有同样的问题。
这是代码,我用它来上传文件到存储,并把将downloadURL在我的数据库
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();
}
}
});
}
错误的堆栈跟踪
2018年10月9日20:32:49.442 9767-9821 / com.example.macbook.firebasemvp E / StorageException:发生StorageException。 用户没有权限访问该对象。 代码:-13021 HttpResult:403 2018年10月9日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:455:火力存储@@ 16.0.2)在com.google.firebase.storage.obfuscated.zzj.zza(COM .google.firebase:火力存储@@ 16.0.2:3435)在com.google.firebase.storage.obfuscated.zzc.zza(com.google.firebase:火力存储@@ 16.0.2:65)在玉米.google.firebase.storage.obfuscated.zzc.zza(com.google.firebase:火力存储@@ 16.0.2:57)在com.google.firebase.storage.zzc.run(com.google.firebase:火力吸藏@@ 16.0.2:68)在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:636)在java.lang中.Thread.run(Thread.java:764)
另外,将文件上传到正确的地方,但仍然出现错误和downloadurl不能放置到数据库
编辑
我缩水的代码和删除的数据库部分还是一样的问题
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();
}
}
});
图片:
此外,没有addOnProgressUpdate
像旧存储实现?