Skip to content
Back

Issue with Appwrite Function Execution – 500 Error in Appwrite Flutter SDK

  • 0
  • Functions
  • Flutter
  • Cloud
Ankit Maniya
6 Jun, 2025, 01:00

Hi all, I'm encountering an issue when calling an Appwrite function from my Flutter app. Environment:

TypeScript
Appwrite Flutter SDK: 16.1.0```
**Problem:**
I'm getting the following error in the Flutter app when calling a function:
```AppwriteException: general_unknown, Server Error (500)
#0      ClientMixin.prepareResponse (package:appwrite/src/client_mixin.dart:90:9)
#1      ClientIO.call (package:appwrite/src/client_io.dart:412:14)
<asynchronous suspension>
#2      Functions.createExecution (package:appwrite/services/functions.dart:63:17)
<asynchronous suspension>
#3      DbBackendClient.sendByteData.<anonymous closure> (package:port_db_backend_client/db/db_client_flutter.dart:307:7)
<asynchronous suspension>
#4      DbBackendClient.sendByteData (package:port_db_backend_client/db/db_client_flutter.dart:296:5)
<asynchronous suspension>
#5      PortDbBackendClient._sendData.<anonymous closure> (package:port_db_backend_client/src/port_db_backend_client_base.dart:93:39)
<asynchronous suspension>

Notes: The function execution appears successful in the Appwrite Console, and I can even see the correct response there. But from the Flutter app, it throws a general_unknown (500) error.

Question: Am I missing something in the response handling, or is this a known issue with the Flutter SDK? Any ideas on how to debug or fix this?

Thanks in advance šŸ™

TL;DR
Developers experiencing a 500 error in function execution via Appwrite Flutter SDK. The issue seems to be related to handling binary data, causing an error for responses exceeding 32 bytes. Action steps involve using a workaround with Base64 encoding and changing the request to `Accept: multipart/form-data`. The problem persists both with the SDK and direct HTTP calls, requiring detailed debugging and possibly a modification in the SDK itself.
Ankit Maniya
6 Jun, 2025, 01:02

My Flutter code

TypeScript
    // and return the response in byte data
    // execute for '/kmsgx' in backend cloud function
    await _functions
        .createExecution(
      functionId: _functionId,
      headers: {
        'Content-Type': 'application/octet-stream',
      },
      path: '/kmsgx',
      method: ExecutionMethod.pOST,
      body: String.fromCharCodes(byteData),
    )
        .then(
      (Execution execution) {
        print('Function executed successfully: ${execution.responseBody}');
        // if it is not UnAuthorized response then responseData with byte data
        if (!execution.responseBody.contains('UnAuthorized')) {
          // codeUnits will return the LIST<int> data
          responseData = Uint8List.fromList(execution.responseBody.codeUnits);
        }
      },
    ).onError((error, stackTrace) {
      print("error, stackTrace :: \n$error, \n $stackTrace");
    });```
Steven
6 Jun, 2025, 17:45

the requests are handled slightly differently when executed via the domain vs the REST endpoint

Ankit Maniya
6 Jun, 2025, 17:47

Ohh I see. I am implementing teams in my flutter app and we are expecting to launch it in August. Can you please see is there anything which can solve this problem?

Steven
6 Jun, 2025, 17:51

can you share minimal function code that reproduces the problem?

Ankit Maniya
6 Jun, 2025, 17:52

Ok, I will share

Ankit Maniya
6 Jun, 2025, 21:11

hello @Steven, sorry for the ping.

I've created a minimal Flutter app that reproduces the same error mentioned in the Discord issue.

The main.dart file in flutter app contains the Appwrite configuration. You can replace it with your own credentials and use a valid user login details.

šŸ”— Flutter App (minimal setup): https://github.com/ankit-maniya/flutter_app_minimul

šŸ”— Minimal Appwrite Function code: https://github.com/ankit-maniya/appwrite_fun_minimul

Let me know if you need any additional details. Thanks!

Ankit Maniya
6 Jun, 2025, 21:25

Issue with Appwrite Function Execution – 500 Error in Appwrite Flutter SDK

Ankit Maniya
10 Jun, 2025, 15:20

Hello @Steven, could you please check this when you get a chance? Sorry for the ping!

Steven
13 Jun, 2025, 01:27

So i do think binary is the problem. Im surprised your other function handles binary responses fine 🧐

Steven
13 Jun, 2025, 01:29

actually i think it depends on the length 🧐

Steven
13 Jun, 2025, 01:31

32 bytes response is fine...but 200 bytes throws an error

Steven
13 Jun, 2025, 01:31

maybe it's a certain byte 🧐

Steven
13 Jun, 2025, 01:37

minimum reproducible function:

TypeScript
Future<dynamic> main(final context) async {
  final b = Uint8List.fromList([128]);
  return context.res.binary(b);
}
Steven
13 Jun, 2025, 01:42

although executing via the function domain doesn't throw 500

Ankit Maniya
13 Jun, 2025, 16:39

Yes, exactly.

Ankit Maniya
13 Jun, 2025, 16:41

This problem is related to function execution using the Appwrite Flutter SDK. Do you have any idea why it behaves differently on the Appwrite server?

Steven
13 Jun, 2025, 17:40

it's not just the flutter sdk

Steven
13 Jun, 2025, 17:44

it happens when the function is executed synchronously via the create executions endpoint

Steven
13 Jun, 2025, 17:48

the endpoint expects input and output to be json so the binary probably screws it up

Steven
13 Jun, 2025, 17:57

ok well it's partly the SDK šŸ˜…

Ankit Maniya
13 Jun, 2025, 17:58

Got it šŸ˜… ! When do you think it will be resolved?

Steven
13 Jun, 2025, 17:58

sooooo if you make the request with Accept: multipart/form-data you'll get multipart data back and it won't throw 500

Steven
13 Jun, 2025, 17:59

i can raise it but might not be soon

Ankit Maniya
13 Jun, 2025, 18:01

Okay, that's good. I also found a workaround. Right now, I’m encoding the request to Base64, and from the function, I'm returning res.text with the encoded Base64 string.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more