8000 Can't connect to Firebase Storage Emulator · Issue #875 · googleapis/java-storage · GitHub
[go: up one dir, main page]

Skip to content
Can't connect to Firebase Storage Emulator #875
@ScottPierce

Description

@ScottPierce

Environment details

  1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
    General, Core, and Other are also allowed as types
  2. OS type and version: osX 10.15.7
  3. Java version: 15
  4. storage version(s): com.google.cloud:libraries-bom:20.4.0

Steps to reproduce

  1. Start the firebase emulator suite (including storage) via the npm firebase client.
  2. Try to create a file using the firetstore emulator

Code example

    fun createStorage(): Storage {
        val storageHost = System.getenv().getOrDefault(ENV_STORAGE_EMULATOR_HOST, "http://localhost:9199")
        println("Using $storageHost for the Storage host")

        return StorageOptions
            .getDefaultInstance()
            .toBuilder()
            .setHost(storageHost)
            .setCredentials(NoCredentials.getInstance())
            .setProjectId("test")
            .build()
            .service
    }
suspend fun Storage.upload(from: InputStream, to: BlobId): Unit = withContext(Dispatchers.IO) {
    val storage = this@upload

    val toInfo = BlobInfo.newBuilder(to).build()

    storage
        .create(toInfo)
        .writer().use { writeChannel ->
            val byteBuffer = ByteBuffer.allocate(2048)

            from.use { from ->
                Channels.newChannel(from).use { fileChannel ->
                    while (fileChannel.read(byteBuffer) > 0) {
                        writeChannel.write(byteBuffer)
                    }
                }
            }
        }
}

Stack trace

Using localhost:8080 for the Firestore host.
It is being configured as an emulator
Using http://localhost:9199 for the Storage host

400 Bad Request
POST http://localhost:9199/upload/storage/v1/b/test/o?projection=full&uploadType=multipart
Bad Request
com.google.cloud.storage.StorageException: 400 Bad Request
POST http://localhost:9199/upload/storage/v1/b/test/o?projection=full&uploadType=multipart
Bad Request
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:233)
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:314)
	at com.goog
69AF
le.cloud.storage.StorageImpl$3.call(StorageImpl.java:221)
	at com.google.cloud.storage.StorageImpl$3.call(StorageImpl.java:218)
	at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
	at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
	at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
	at com.google.cloud.storage.StorageImpl.internalCreate(StorageImpl.java:217)
	at com.google.cloud.storage.StorageImpl.create(StorageImpl.java:157)
	at com.example.test.ProcessController$upload$4.invokeSuspend(ProcessorController.kt:118)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
POST http://localhost:9199/upload/storage/v1/b/test/o?projection=full&uploadType=multipart
Bad Request
	at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
	at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:118)
	at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:37)
	at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:532)
	at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:455)
	at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:565)
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:311)
	... 14 more

It seems like maybe this library doesn't support the local emulator.

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/java-storage API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0