Skip to content

Bug(android): Attempting Upload with Params Causes "Unknown Error" #30

@dougahall

Description

@dougahall

Bug Report

When attempting to upload a file from Android and including params, I keep getting the following error:

"message":"The operation failed with an error - An unknown error occurred while trying to run the operation"
"code":"OS-PLUG-FLTR-0011"

Capacitor Version

   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/ios: not installed
  @capacitor/cli: 7.4.1
  @capacitor/android: 7.4.1
  @capacitor/core: 7.4.1

[success] Android looking great! 👌

using @capacitor/file-transfer v1.0.6

Platform(s)

Android.
Not attempted on iOS.

Current Behavior

An exception is thrown before the file is uploaded.

Here is the simplified code attempting the upload:

		const uri = (await Filesystem.getUri({directory: Directory.Data, path: 'image.jpg'})).uri;

		const result = await FileTransfer.uploadFile({
			url: 'https://my.backend.com/upload,
			path: uri,
			fileKey: 'file', // The key expected by the server for the file
			headers: {
				api_key: '...key...'
			}, params: {
				fileName: 'image.jpg'
			}
		});

Digging in, there is this exception being thrown:

java.lang.IllegalStateException: Cannot set request property after connection is made

The exception is in IONFLTRController.kt at line 284:

            connection.setRequestProperty("Content-Type", mimeType)

Expected Behavior

File is uploaded without error.

Code Reproduction

Other Technical Details

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions