skip to Main Content

Using Firebase tools 11.21.0 and FIREBASE_STORAGE_EMULATOR_HOST=localhost:9199 and maven dependency

<dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-storage</artifactId>
      <version>2.17.1</version>
</dependency>

I started the firebase emulator. And tried a simple file store:

emulatorStorage = StorageOptions.newBuilder()
                    .setProjectId(projectId)
                    .setHost("http://localhost:9199")
                    .setCredentials(NoCredentials.getInstance())   
                    .build()
                    .getService();

And tried to save a file:

 byte[] compress = "test".getBytes();
           
            Blob blob = emulatorStorage.create(
                    BlobInfo.newBuilder(index, filename)
                            .setContentType("text/plain")
                            .build()
                    ,compress,
                    Storage.BlobTargetOption.doesNotExist());

but even with the content type set I get this every time:

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)

and through debug I know that it is talking to the local emulator:

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."
}

What am I missing in the save operation, is the content type wrong? Or is this likely to be a bug in the emulator or compatibility issue with cloud-storage libs?

2

Answers


  1. As mentioned by @Gridcell Coder, The Cloud Storage for Firebase emulator only supports a very small subset of the Cloud API and it is intended to only be used via the firebase-admin package. Admin SDK is not yet supported for Cloud Storage for Firebase.

    Login or Signup to reply.
  2. I have found github issue you raised and followed steps from there with both firebase v11.21.0 And v11.19.0 but I can successfully upload video files using firebase emulators:start --project demo-project --debug.

    As per our conversation above in comments, it seems like you have mistaken firebase-tools-linux as a command. the doc you followed to set up the forebase for linux will just have downloadable file name as firebase-tools-linux It is just file name it does not mean that for linux we have to use firebase-tools-linux as a command for linux machines.If you observe step 3 in the doc you shared, It is pointing to log in and test the CLI where we have to use firebase login only. Hence try with firebase emulators:start --project demo-project --debug command.

    Steps I have taken

    Step 1:
    Cloned source code from the github you shared. Changed directory to firebase-emulator-debug.

    Step 2:
    Ran below command

    `firebase emulators:start --project demo-project --debug`.
    

    Step 3:
    Successfully uploaded video file of 2.3 MB from emulator.

    FYI, I have also used the linux machine only for the above steps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search