Firebase存储异常

时间:2017-10-03 09:55:26

标签: android firebase firebase-storage

我的代码工作正常,但今天我得到了这个例外,任何人都可以提供帮助吗?日志已附加 感谢

10-03 13:33:50.141 15352-17764/com.shahzain.ada E/StorageException: StorageException has occurred.
                                                                              An unknown error occurred, please check the HTTP result code and inner exception for server response.


Code: -13000 HttpResult: 200
10-03 13:33:50.141 15352-17764/com.shahzain.ada E/StorageException: the maximum allowed buffer size was exceeded.
                                                                          java.lang.IndexOutOfBoundsException: the maximum allowed buffer size was exceeded.
                                                                              at com.google.firebase.storage.StorageReference$5.doInBackground(Unknown Source)
                                                                              at com.google.firebase.storage.StreamDownloadTask.run(Unknown Source)
                                                                              at com.google.firebase.storage.StorageTask$8.run(Unknown Source)
                                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                              at java.lang.Thread.run(Thread.java:818)
10-03 13:33:50.141 15352-17764/com.shahzain.ada E/StorageException: StorageException has occurred.
                                                                          An unknown error occurred, please check the HTTP result code and inner exception for server response.
                                                                           Code: -13000 HttpResult: 200
10-03 13:33:50.141 15352-17764/com.shahzian.ada E/StorageException: the maximum allowed buffer size was exceeded.
                                                                          java.lang.IndexOutOfBoundsException: the maximum allowed buffer size was exceeded.
                                                                              at com.google.firebase.storage.StorageReference$5.doInBackground(Unknown Source)
                                                                              at com.google.firebase.storage.StreamDownloadTask.run(Unknown Source)
                                                                              at com.google.firebase.storage.StorageTask$8.run(Unknown Source)
                                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                              at java.lang.Thread.run(Thread.java:818)

这是代码,用于从firebase存储下载内容

final long ONE_MEGABYTE = 1024 * 1024;
islandRef.getBytes(ONE_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
    @Override
    public void onSuccess(byte[] bytes) {
        // Data for "images/island.jpg" is returns, use this as needed
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle any errors
    }
});

3 个答案:

答案 0 :(得分:4)

我通过超出代码大小修正了上面的问题,第一个大小是1mb,后来我把它增加到了5mb。

final long ONE_MEGABYTE = 1024 * 1024;

将此更改为更大的尺寸,例如

final long ONE_MEGABYTE = 1024 * 1024 *5;

答案 1 :(得分:0)

请检查Google Play服务是否是最新的。如果没有更新。如果它是最新的清除谷歌播放服务的缓存内存。

答案 2 :(得分:-2)

我认为最好的解决方案是使用另一种下载方法。因为它必须将文件的全部内容加载到内存中。如果您请求的文件大于应用程序的可用内存,则您的应用程序将崩溃。

您应该通过网址使用下载数据:

storageRef.child("users/me/profile.png").
getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
        @Override
        public void onSuccess(Uri uri) {
            // Got the download URL for 'users/me/profile.png'
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle any errors
        }
    });

在您的imageview中,您使用Glide来展示它:

Glide.with(MainActivity.this)
 .load(mFirebaseUser.getPhotoUrl())
 .into(mYourImageView);`