firebase / firebase-tools

The Firebase Command Line Tools
MIT License
3.98k stars 918 forks source link

Unable to store file to emulator storage using google-cloud libraries: Failed to parse multipart request body part. Missing content type. #5451

Open gridcellcoder opened 1 year ago

gridcellcoder commented 1 year ago

[REQUIRED] Environment info

firebase-tools:11.21.0

Platform

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:    22.04
Codename:   jammy

[REQUIRED] Test case

FIREBASE_STORAGE_EMULATOR_HOST=localhost:9199

Create a basic maven project with google-cloud libs and start the emulator (after running firebase init).

Complete code example here; https://github.com/gridcellcoder/firebase-emulator-debug

[REQUIRED] Steps to reproduce

firebase-tools-linux emulators:start --project demo-project --debug

Then create a maven project only with latest cloud libs

<dependencies>
        <!-- https://mvnrepository.com/artifact/com.google.api-client/google-api-client -->
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>2.1.3</version>
        </dependency>

        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-storage</artifactId>
            <version>2.17.1</version>
        </dependency>
    </dependencies>
Storage emulatorStorage = StorageOptions.newBuilder()
                .setProjectId("demo-project")
                .setHost("http://localhost:9199")
                .setCredentials(NoCredentials.getInstance())
                .build()
                .getService();

        emulatorStorage.create(
                BlobInfo.newBuilder("demo-project.appspot.com", "test")
                        .setContentType("text/plain")
                        .build()
                ,"test".getBytes(),
                Storage.BlobTargetOption.doesNotExist());

results in an exception.

Other steps and approaches also indicated at stackoverflow: https://stackoverflow.com/questions/75201025/unable-to-upload-media-file-tofirebase-emulator

tried with combinations of google-cloud-storage 2.15.0,2.16.0 and firebase-tools v11.19.0 ,v11.16.1 and get the same error message.

[REQUIRED] Expected behavior

Storage of a text file in the emulated storage bucket gs://demo-project.appspot.com as seen in the UI.

[REQUIRED] Actual behavior

Exception in thread "main" com.google.cloud.storage.StorageException: Failed to parse multipart request body part. Missing content type.
    at com.google.cloud.storage.StorageException.translate(StorageException.java:163)
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:297)
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:379)
    at com.google.cloud.storage.StorageImpl.lambda$internalCreate$2(StorageImpl.java:208)
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:103)
    at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
    at com.google.cloud.storage.Retrying.run(Retrying.java:60)
    at com.google.cloud.storage.StorageImpl.run(StorageImpl.java:1476)
    at com.google.cloud.storage.StorageImpl.internalCreate(StorageImpl.java:205)
    at com.google.cloud.storage.StorageImpl.create(StorageImpl.java:151)
    at org.example.Main.main(Main.java:17)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
POST http://localhost:9199/upload/storage/v1/b/demo-project.appspot.com/o?ifGenerationMatch=0&projection=full&uploadType=multipart
{
  "code" : 400,
  "message" : "Failed to parse multipart request body part. Missing content type."
}
    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:570)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:493)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:603)
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:376)
    ... 9 more

logfile.txt

google-oss-bot commented 1 year ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

gridcellcoder commented 1 year ago

Its possible its just not supported yet https://github.com/googleapis/java-storage/issues/875 https://firebase.google.com/docs/emulator-suite/install_and_configure#admin_sdk_availability

spiropulo commented 1 year ago

Any updates on this? Is it supported or not? Can we use the cloud store emulator in tests?