diff --git a/pkgs/cronet_http/lib/src/cronet_client.dart b/pkgs/cronet_http/lib/src/cronet_client.dart index f55617eeb1..28ac921f84 100644 --- a/pkgs/cronet_http/lib/src/cronet_client.dart +++ b/pkgs/cronet_http/lib/src/cronet_client.dart @@ -392,8 +392,19 @@ class CronetClient extends BaseClient { headers.forEach((k, v) => builder.addHeader(k.toJString(), v.toJString())); if (body.isNotEmpty) { + final JByteBuffer data; + try { + data = body.toJByteBuffer(); + } on JniException catch (e) { + if (e.message.contains('java.lang.OutOfMemoryError:')) { + throw ClientException( + 'Not enough memory for request body: ${e.message}', request.url); + } + rethrow; + } + builder.setUploadDataProvider( - jb.UploadDataProviders.create2(body.toJByteBuffer()), _executor); + jb.UploadDataProviders.create2(data), _executor); } builder.build().start(); return responseCompleter.future;