Firebase存储10.2.6 - >无法打开结果流

时间:2017-05-17 23:55:19

标签: android firebase firebase-storage

我有新的Firebase存储SDK,即10.2.6。当我尝试下载文件时,我收到此错误。以前在10.2.1我没有问题。

I/DynamiteModule: Considering local module com.google.android.gms.firebasestorage:0 and remote module com.google.android.gms.firebasestorage:6
I/DynamiteModule: Selected remote version of com.google.android.gms.firebasestorage, version >= 6
V/FA: Activity resumed, time: 148646549
D/debugStorageListener: onSuccess: -1
D/OpenGLRenderer: endAllActiveAnimators on 0x7219a63c00 (RippleDrawable) with handle 0x721ad62fe0
W/System.err: java.io.IOException: Could not open resulting stream.
W/System.err:     at com.google.firebase.storage.StreamDownloadTask.zzadq(Unknown Source)
W/System.err:     at com.google.firebase.storage.StreamDownloadTask.zza(Unknown Source)
W/System.err:     at com.google.firebase.storage.StreamDownloadTask$1.zzads(Unknown Source)
W/System.err:     at com.google.firebase.storage.StreamDownloadTask$1.call(Unknown Source)
W/System.err:     at com.google.firebase.storage.StreamDownloadTask$zza.zzadu(Unknown Source)
W/System.err:     at com.google.firebase.storage.StreamDownloadTask$zza.read(Unknown Source)
W/System.err:     at java.io.BufferedInputStream.read1(BufferedInputStream.java:273)
W/System.err:     at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
W/System.err:     at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:287)
W/System.err:     at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:350)
W/System.err:     at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:179)
W/System.err:     at java.io.InputStreamReader.read(InputStreamReader.java:184)
W/System.err:     at java.io.Reader.read(Reader.java:140)
W/System.err:     at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2001)
W/System.err:     at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1980)
W/System.err:     at org.apache.commons.io.IOUtils.copy(IOUtils.java:1957)
W/System.err:     at org.apache.commons.io.IOUtils.copy(IOUtils.java:1907)
W/System.err:     at org.apache.commons.io.IOUtils.toString(IOUtils.java:778)
W/System.err:     at org.apache.commons.io.IOUtils.toString(IOUtils.java:759)
W/System.err:     at eu.long1.jwnotes.services.ReceiveService.lambda$handleDownload$2$ReceiveService(ReceiveService.java:186)
W/System.err:     at eu.long1.jwnotes.services.ReceiveService$$Lambda$2.onResult(Unknown Source)
W/System.err:     at eu.long1.jwnotes.helpers.firebase.StorageListener$1.doInBackground(StorageListener.java:48)
W/System.err:     at eu.long1.jwnotes.helpers.firebase.StorageListener$1.doInBackground(StorageListener.java:45)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:305)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err:     at java.lang.Thread.run(Thread.java:761)

在崩溃之前,我得到了这个信息:

I/DynamiteModule: Considering local module com.google.android.gms.firebasestorage:0 and remote module com.google.android.gms.firebasestorage:6
I/DynamiteModule: Selected remote version of com.google.android.gms.firebasestorage, version >= 6

编辑:

当然在这里:

private void handleDownload(final String key, ArrayList<String> locations, ArrayList<Talk> talks) {
        for (String location : locations) {
            DatabaseH.getShareTalksReference().child(key).child(location).setValue(null);
        }


        int[] downloadCount = {talks.size()};
        log.d(downloadCount);

        for (final Talk talk : talks) {
            new StorageListener(StorageH.getStream(talk.getPath()), (task) -> {
                try {
                    File file = new File(sTalksFolder, talk.getFileName());
                    talk.setPath(file.getAbsolutePath());

                    InputStream inputStream = task.getResult().getStream();
                    String fileContent = IOUtils.toString(inputStream);
                    TalkFile talkFile = new TalkFile(fileContent);
                    talkFile.setTalk(talk);

                    IOUtils.copy(IOUtils.toInputStream(talkFile.toString()), new FileOutputStream(file));

                    downloadCount[0]--;

                    if (downloadCount[0] == 0) {
                        ReceivedDB.getInstance(context).deleteReceived(locations);
                        SendMessagingService.received(getApplicationContext(), locations);
                        FileSyncService.addFiles(getBaseContext(), talks);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
        }
    }

这是getStream()方法:

public static StreamDownloadTask getStream(String url) {
        return FirebaseStorage.getInstance().getReferenceFromUrl(url).getStream();
}

1 个答案:

答案 0 :(得分:1)

我知道这已经有一段时间了,但是如果有人知道了,我为解决此问题所做的只是修改访问项目的规则

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

我认为默认情况下它希望对用户进行身份验证,但是出于开发目的,我删除了if语句。您可以在“存储”部分下的“规则”标签中找到此