Skip to content

FirebaseAppDistributionApi().media.upload() failing to upload #677

@AbhijithKonnayil

Description

@AbhijithKonnayil

follow up of issue : #674

When trying to upload apk to firebase app distribution with FirebaseAppDistributionApi it fails with 400 without proper error message on what is the issue in the request.

DetailedApiRequestError(status: 400, message: No error details. HTTP status was: 400.)

I checked with the google-api-python-client and the firebase app distribution api is working fine in python and APK has successfully uploaded to firebase.

I compared the curl request sent by the python client and googleapis.dart.

The critical differences are as follows

Header Python dart
content-type application/vnd.android.package-archive multipart/related; boundary="314159265358979323846"
content-length 18,935,247 (actual apk size) 25,247,203

I experimented with the googleapis.dart and here are my findings

  1. The protocol mentioned in disovery apis is simple with multipart set to true
            "protocols": {
                     "simple": {
                                "multipart": true,
                                "path": "/upload/v1/{+app}/releases:upload"
                            }
                        }
  1. APK will get uploaded when using the simpleUpload() in discoveryapis_commons > api_requester.dart > ApiRequester - class > _request().
    1. But it will use simpleUpload() only if body parameter in _request() is null.
    2. The body parameter gets its value by JSON encoding the request object passed to upload() in generated > googleapis > firebaseappdistribution > v1.dart > MediaSource - class > upload()
      async.Future<GoogleLongrunningOperation> upload(
          GoogleFirebaseAppdistroV1UploadReleaseRequest request,
          core.String app, {
          core.String? $fields,
          commons.Media? uploadMedia,
        }) async {
          final body_ = convert.json.encode(request);
    3. Even if the requeset passed to upload has no paramentes passed , it will enocode as "{}"
    4. The toJson() method in GoogleFirebaseAppdistroV1UploadReleaseRequest is non nullable

in short , to upload using simpleUpload() the body_ should be null

  1. By default , the package tries to upload using MultipartMediaUploader-class > upload()
    1. Here the content type is chaneged to multipart/related; boundary="314159265358979323846" and the content length is changed accordingly to combine Json data and encoded binary file.

    . Are we supposed to use this for upload. The rest api in firebase mention only about binary as body. https://firebase.google.com/docs/reference/app-distribution/rest/v1/upload.v1.projects.apps.releases/upload#http-request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions