no access to result of downloadUrl in Firebase Storage emulator

Viewed 76

I try to test my app with the Firebase Emulator Suite, especially I'm using the Storage emulator.

Now I try to get access to a successfully uploaded image via the downloadURL method and passing them into a FileInputStream. Unfortunately I get an java.io.FileNotFoundException.

I think the reason is, because the resulting URL from downloadURLstarted with http:/10.0.2.2:9199 instead of http:/localhost:9199. Substitute 10.0.2.2with localhostand pasting the URL in a browser shows the image.

Here are my code snippets:

Firebase.storage.useEmulator("10.0.2.2", 9199)
...
val imageKey = getNewImageStorageKey()!!+".jpg"
val outputStream = ByteArrayOutputStream()
bitmapToUpload.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)

mStorageProductImageReference.child(imageKey).putBytes(outputStream.toByteArray()).await()
var imageURL = mStorageProductImageReference.child(imageKey).downloadUrl.await()
val inputStream = FileInputStream(imageURL.toString())

This leads to following error:

java.io.FileNotFoundException: http:/10.0.2.2:9199/v0/b/myapp-e02f1.appspot.com/o/product_images%2F-aQD1EpITebrYZnMtKOq.jpg?alt=media&token=97f3bc03-4f23-4b95-a8a0-70245bfbae91

The Storage emulator is running on:

│ Storage        │ localhost:9199                   │ http://localhost:4000/storage 

I'm an a MacOS system if this is relevant.

Any suggestions on how to use the result from downloadURL to get access to the uploaded image in the Firebase Storage emulator?

1 Answers

I'm so damn st....

While hitting the post button, the resolution came into my mind.

I can not use a FileInputStream for a http request. Sorry for that.

With a simple:

val connection = URL(imageURL.toString()).openConnection() as HttpURLConnection
val resultBitmap = BitmapFactory.decodeStream(connection.inputStream)

I could confirm that uploading and downloading is working.

Related