【问题标题】:Firebase Storage exceptionFirebase 存储异常
【发布时间】:2018-05-15 21:02:46
【问题描述】:

我的代码运行良好,但今天我遇到了这个异常,有人可以帮忙吗?日志已附加 谢谢

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
    }
});

【问题讨论】:

  • "寻求调试帮助的问题('为什么这段代码不起作用?')必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确的问题陈述对其他读者没有用处。见:How to create a Minimal, Complete, and Verifiable example."
  • 我无法弄清楚代码的确切部分,我知道它在 firebase 存储中,但它适用于某些视频并为某些视频抛出异常,后来我回答了我的问题,谢谢。
  • 顺便说一句,谢谢@FrankvanPuffelen,你在与 firebase 相关的问题上帮助了我很多:)
  • 很高兴听到您找到了问题的原因!

标签: android firebase firebase-storage


【解决方案1】:

我已经解决了上述问题,代码中的大小超过了第一个大小为 1mb ,后来我将其增加到 5mb。

final long ONE_MEGABYTE = 1024 * 1024;

把它改成更大的尺寸,比如

final long ONE_MEGABYTE = 1024 * 1024 *5;

【讨论】:

    【解决方案2】:

    请检查 google play 服务是否是最新的。如果没有更新。如果是最新的,请清除 google play 服务的缓存。

    【讨论】:

      【解决方案3】:

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

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

      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);`
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-05
        • 1970-01-01
        • 1970-01-01
        • 2018-04-26
        • 2017-03-26
        • 2020-02-29
        • 1970-01-01
        • 2020-08-02
        相关资源
        最近更新 更多