Firebase存储10.2.6 - >无法打开生成的流

问题描述 投票:5回答:1

我有新的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();
}
android firebase firebase-storage
1个回答
1
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.