Issue with Appwrite Function Execution ā 500 Error in Appwrite Flutter SDK
- 0
- Functions
- Flutter
- Cloud

Hi all, I'm encountering an issue when calling an Appwrite function from my Flutter app. Environment:
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 š

My Flutter code
// 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");
});```

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

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?

can you share minimal function code that reproduces the problem?

Ok, I will share

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!

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

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

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

actually i think it depends on the length š§

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

maybe it's a certain byte š§

minimum reproducible function:
Future<dynamic> main(final context) async {
final b = Uint8List.fromList([128]);
return context.res.binary(b);
}

although executing via the function domain doesn't throw 500

Yes, exactly.

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?

it's not just the flutter sdk

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

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

ok well it's partly the SDK š

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

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

i can raise it but might not be soon

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.
Recommended threads
- Appwrite Fra Cloud Custom Domains Issue
Iām trying to configure my custom domain appwrite.qnarweb.com (CNAME pointing to fra.cloud.appwrite.io with Cloudflare proxy disabled) but encountering a TLS ce...
- Storage & Database is not allowing.
Storage & Database is not allowing to CRUD after i have logged in ? Using web SDK with next.js without any SSR or node-sdk.
- session client not allowed to create doc...
Hello all! So my issue is that I keep getting ERROR Error creating invitation: The requested service is disabled. You can enable the service from the Appwr...
