我是firebase存储的新手.就这样我可以学习它,我做了一个简单的应用程序,它有一个按钮和一个ImageVIEw.当我单击按钮时,ImageVIEw上会显示一个图像(来自drawable).我还编写了在Firebase上上传图像的代码,但是onAddFailureListener的异常消息给出了消息User没有访问此对象的权限.我该怎么办 ?
package com.example.asad.save_photo;import androID.app.Activity;import androID.graphics.Bitmap;import androID.os.Bundle;import androID.net.Uri;import androID.os.Environment;import androID.support.annotation.NonNull;import androID.support.v7.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.ImageVIEw;import androID.Widget.Toast;import com.Google.androID.gms.tasks.OnFailureListener;import com.Google.androID.gms.tasks.OnSuccessListener;import com.Google.firebase.storage.FirebaseStorage;import com.Google.firebase.storage.StorageMetadata;import com.Google.firebase.storage.StorageReference;import com.Google.firebase.storage.UploadTask;import java.io.ByteArrayOutputStream;import java.io.file;public class MainActivity extends AppCompatActivity { @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); FirebaseStorage storage = FirebaseStorage.getInstance(); StorageReference storageRef = storage.getReferenceFromUrl("gs://savephoto-a1cc3.appspot.com"); final StorageReference mountainsRef = storageRef.child("asad"); button butt = (button) findVIEwByID(R.ID.button); butt.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { ImageVIEw imageVIEw = (ImageVIEw) findVIEwByID(R.ID.image); imageVIEw.setimageResource(R.drawable.back2); //imageVIEw.setimageResource(R.drawable.back2); imageVIEw.setDrawingCacheEnabled(true); imageVIEw.buildDrawingCache(); Bitmap bitmap = imageVIEw.getDrawingCache(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); final byte[] data = baos.toByteArray(); UploadTask uploadTask = mountainsRef.putBytes(data); uploadTask.addOnFailureListener(new OnFailureListener() { @OverrIDe public voID onFailure(@NonNull Exception exception) { // Handle unsuccessful uploads showToast(exception.getMessage()); } }); uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @OverrIDe public voID onSuccess(UploadTask.TaskSnapshot taskSnapshot) { // taskSnapshot.getMetadata() contains file Metadata such as size, content-type, and download URL. //Uri downloadUrl = taskSnapshot.getDownloadUrl(); showToast("success !!!!!"); } }); } }); } public voID showToast(String s) { Toast.makeText(this,s,Toast.LENGTH_LONG).show(); }}
这是我的firebase存储规则
service firebase.storage { match /b/savephoto-a1cc3.appspot.com/o { allow read,write; }}
解决方法:
使用匹配/ {allPaths = **}更新安全规则,以指示所有路径上都允许公共读写访问:
service firebase.storage { match /b/savephoto-a1cc3.appspot.com/o { match /{allPaths=**} { // Allow access by all users allow read, write; } }}
文档的Sample Rules部分的选项卡中提供了各种默认规则.
总结以上是内存溢出为你收集整理的用户无权访问此对象. Firebase存储android全部内容,希望文章能够帮你解决用户无权访问此对象. Firebase存储android所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)