【发布时间】:2018-02-06 10:06:25
【问题描述】:
当用户单击我的聊天应用程序中的某个按钮时,我正在尝试将图像上传到 Firebase 存储,但它不起作用。
这是上传代码
if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
StorageReference photoRef = mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment());
photoRef.putFile(selectedImageUri)
.addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// When the image has successfully uploaded, we get its download URL
Uri downloadUrl = taskSnapshot.getDownloadUrl();
// Set the download URL to the message box, so that the user can send it to the database
FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUrl.toString());
mDatabaseReference.push().setValue(friendlyMessage);
}
});
}
【问题讨论】:
-
你遇到了什么错误?
-
有错误吗?会不会是身份验证问题?
-
在您的应用控制台中检查 Firebase 存储规则,如果您没有使用任何 Firebase 身份验证方法,那么您的规则必须允许对所有用户(不仅仅是经过身份验证的用户)进行读写才能上传或下载任何文件。
-
我没有收到任何错误消息,它只是没有将任何内容上传到数据库。我不认为这是一个身份验证问题,普通短信可以正常工作,并且它具有与图像相同的规则“service firebase.storage { match /b/{bucket}/o { match /{allPaths=**} { allow read,写:如果 request.auth != null; } } }"
-
@tokaaliamien 它会上传到存储吗?
标签: android firebase firebase-storage