firebase / firebase/firebase-tools

FR: [Storage Emulator] Support googleapis/java-storage

Open
#3,508 6 comments 1 reaction 1 assignee Assigned to @abhis3 View on GitHub
emulator-suite emulators: storage type: feature request
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

This bug was copied from https://github.com/googleapis/java-storage/issues/875 as it was indicated that it might be a bug with the emulator, not the java client.

#### 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

```Kotlin
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
}
```

```Kotlin
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.google.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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.