Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Storage 10.2.6 -> Could not open resulting stream

I have and issue with the new Firebase Storage SDK, namely 10.2.6. When I try do download a file I get this error. Previously in the 10.2.1 I had no problem.

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)

Just before the crash I get this info:

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

EDIT:

Sure here it is:

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

This is the getStream() method:

public static StreamDownloadTask getStream(String url) {
        return FirebaseStorage.getInstance().getReferenceFromUrl(url).getStream();
}
like image 701
Razvan Cristian Lung Avatar asked May 17 '17 23:05

Razvan Cristian Lung


1 Answers

I know this has been out for a while, but if anyone gets this, what I did to resolve this issue is just modifying the rule for accessing the item

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

I think by default it wants the user to be authenticated, but for dev purposes I removed that if statement. You'll find this in the rules tab under the storage section

like image 189
user9333933 Avatar answered Oct 23 '22 02:10

user9333933