Skip to content

UploadFile on Android returns a wrong server response #26

@ov77

Description

@ov77

Bug Report

Capacitor Version

1.0.5

   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 7.4.3
  @capacitor/core: 7.4.3
  @capacitor/android: 7.4.3
  @capacitor/ios: 7.4.3

Installed Dependencies:

  @capacitor/android: 7.4.3
  @capacitor/cli: 7.4.3
  @capacitor/core: 7.4.3
  @capacitor/ios: 7.4.3

[error] Xcode is not installed
[success] Android looking great! 👌

Platform(s)

Android

Current Behavior

Try to upload a file to a server that should return a json response after upload.

const r = await FileTransfer.uploadFile({
    "readTimeout": 2000,
    "connectTimeout": 2000,
    "headers": {
        "X-XXX-Api-Client": "native-mobile",
        "X-XXX-Session": "128b08fb4d606ce2654d6fe2c8bf7868"
    },
    "webFetchExtra": {
        "credentials": "include",
        "keepalive": true
    },
    "url": "http://192.168.4.230:8000/api/v1/temporaryAttachments",
    "path": "file:///data/user/0/com.mydomain.app/cache/ovidiu%40localdomain/drafts-temp-attachments/5349141896_30062a32-d96b-41e6-8755-3996db03564f.pdf",
    "fileKey": "filename",
    "mimeType": "application/pdf"
});

The response looks like:

{ "bytesSent": 93215, "responseCode": "200", "response": "\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u00005��\u000e�0\u0010D�e�T[�]Y���7cL�%�DJ\u0013zQ¿[c<μ7����l��v��Tb*C�\u001e����+�Z���2�\"k:�0W.��\u0006�_�ܡecM��@���ت�4*k\"���Bf\n�FGv>�>6y�1�6|܏\u000f\u0003c���\u0000\u0000\u0000", "headers": "{null=[HTTP/1.1 200 OK], Access-Control-Allow-Credentials=[true], Access-Control-Allow-Headers=[Content-Type, X-Requested-With, Authorization, X-XXX-Session, X-XXX-Api-Client], Access-Control-Allow-Methods=[GET, POST, PUT, PATCH, DELETE, OPTIONS], Access-Control-Allow-Origin=[http://localhost:8100], Access-Control-Expose-Headers=[X-XXX-2FA], Access-Control-Max-Age=[86400], Allow=[GET, POST], Connection=[Keep-Alive], Content-Encoding=[gzip], Content-Length=[139], Content-Type=[application/json; charset=utf-8], Date=[Mon, 8 Sep 2025 07:42:29 GMT], Pragma=[no-cache], Referrer-Policy=[no-referrer], Server=[XXX-Webmail], X-Android-Received-Millis=[1757317349150], X-Android-Response-Source=[NETWORK 200], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1757317349131]}" }

Expected Behavior

The field response should contain a text representing a JSON object (the server's response).

Code Reproduction

Other Technical Details

I even tried to send a custom value for Accept-Encoding header, but the capacitor always send Accept-Encoding: gzip

I used WireShark to see the call and the response. As you can see the server response looks ok.

Call:

Image

Response:

Image

Additional Context

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