google / google/googleapis.dart

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

Open
#677 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
419
Forks
136
Avg merge
1h 21m
Merged PRs (30d)
5

Description

follow up of issue : https://github.com/google/googleapis.dart/issues/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"
}
}
```
2. 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()`
```dart
async.Future 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`

3. 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

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.