ajinasokan / flutter_curl Goto Github PK
View Code? Open in Web Editor NEWFlutter plugin to use libcurl for HTTP calls
License: MIT License
Flutter plugin to use libcurl for HTTP calls
License: MIT License
This is what I get as soon as I import the package into a project file. This happens even with the latest dependency version.
../../../../.pub-cache/hosted/pub.dev/flutter_curl-0.1.1/lib/src/ffi.dart:12:8: Error: Field 'messageType' cannot be nullable or have type 'Null', it must be
int,
double,
Pointer, or a subtype of
Structor
Union. int? messageType; ^ ../../../../.pub-cache/hosted/pub.dev/flutter_curl-0.1.1/lib/src/ffi.dart:14:27: Error: Field 'easyHandle' cannot be nullable or have type 'Null', it must be
int,
double,
Pointer, or a subtype of
Structor
Union. ffi.Pointer<_CURLEasy>? easyHandle; ^ ../../../../.pub-cache/hosted/pub.dev/flutter_curl-0.1.1/lib/src/ffi.dart:17:8: Error: Field 'result' cannot be nullable or have type 'Null', it must be
int,
double,
Pointer, or a subtype of
Structor
Union. int? result; ^
If you'd like to help, that'd be great.
Performing hot restart...
Restarted application in 2,422ms.
flutter: libcurl/7.88.1-DEV BoringSSL zlib/1.2.11 brotli/1.0.9 nghttp2/1.52.0 quiche/0.16.0
flutter: Error: SSL peer certificate or SSH remote key was not OK
flutter: Status: 0
flutter: HTTP: HTTPVersion.unknown
flutter:
code:
void main() async {
// Initialize client
final client = curl.Client(
verbose: true,
interceptors: [
// HTTPCaching(),
],
);
await client.init();
// Send request
final res = await client.send(curl.Request(
method: "GET",
url: "https://ajinasokan.com/",
));
// Read response
print("Error: ${res.errorMessage}");
print("Status: ${res.statusCode}");
print("HTTP: ${res.httpVersion}");
res.headers.forEach((key, value) {
print("$key: $value");
});
print(res.text());
}
flutter version: 3.13.7
But it's normal on Android, what can i do?
..../flutter_curl/macos/Classes/FlutterCurlPlugin.m:11:18: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void curl_version();
^
void
1 warning generated.
ld: warning: ignoring file ..../flutter_curl/macos/Curl.framework/Curl, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
"_curl_version", referenced from:
+[FlutterCurlPlugin registerWithRegistrar:] in FlutterCurlPlugin.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')
** BUILD FAILED **
could you share an SOP on rebuilding Curl.framework from scratch
Hi,
I'm new to flutter_curl, but I use curl a lot, can you tell me how to use flutter_curl to retrive verbose info, just like get output from curl -v $url
On desktop, it says
Failed to load dynamic library '/home/meisme/AndroidStudioProjects/minebird/build/linux/x64/debug/bundle/lib/libcurl.so': /home/meisme/AndroidStudioProjects/minebird/build/linux/x64/debug/bundle/lib/libcurl.so: cannot open shared object file: No such file or directory
I know there's a .so file in Releases, but I'm unsure where to place it. Do I manually place the file every time I build?
Excpected goal:
I want to upload files to multipart API using these plugins:
but it gives me "MimeMultipartException: Bad multipart ending", however it works perfectly executed in CMD as shown below
curl -H "Content-Type: multipart/mixed" -F id=2 -F [email protected] -F [email protected] -F [email protected] -F [email protected] -F [email protected] -F [email protected] -F [email protected] -F [email protected] http://127.0.0.1:8080/test_upload
HOW I can achive this using flutter_curl? or what is the solution to this problem?
here are some supporting attachments:
Future<Response> upload(Request request) async {
try {
// final description = StringBuffer('Regular multipart request\n');
int audioFileCount = 1;
Map<String, String> data = {};
await for (final part in request.parts) {
String content = part.headers['content-disposition'];
if (content.contains('name="id"')) {
data.addAll({
'id': await part.readString(),
});
} else if (content.contains('name="audio_$audioFileCount"')) {
Uint8List file = await part.readBytes();
data.addAll({
'mfcc_$audioFileCount': extractMfcc(file)
.toString(), // looks like --> mfcc_1: [[10.1209..], [10.1217..], ..]
});
audioFileCount++;
}
}
print(data);
if (audioFileCount != 9) {
return Response.forbidden('Fields not filled perfectly.');
}
Map<String, dynamic> result = await model.updateMFCC(data);
if (result['status']) {
return Response.ok(json.encode({
'status': true,
'message': 'Complete processing.',
}));
} else {
return Response.ok(json.encode({
'status': false,
'message': 'Processing failed.',
}));
}
} on FormatException catch (e) {
return Response.internalServerError(
body: '!!EXCEPTION!!\n${e.toString()}\n${e.message.toString()}');
} on Exception catch (e) {
print(e
.toString()); // Produced: "MimeMultipartException: Bad multipart ending"
return Response.internalServerError(
body: '!!EXCEPTION!!\n${e.toString()}');
}
}
String path = 'test_upload';
APIMethod method = APIMethod.post;
Map<String, String>? parameters = {'id': '1'};
List<File> files = const [File('path/to/file.wav'), File('path/to/file.wav'), ...];
List<String> fields = const ['audio_1', 'audio_2', ...];
Client client = Client(
verbose: true,
interceptors: [
// HTTPCaching(),
],
);
await client.init();
List<Multipart> multiparts = [];
parameters.forEach((key, value) {
multiparts.add(Multipart(
name: key,
data: value,
));
});
if (files.isNotEmpty && fields.isNotEmpty) {
if (files.length == fields.length) {
for (var i = 0; i < files.length; i++) {
multiparts.add(
Multipart.file(
name: fields[i],
path: files[i].path,
filename: "audio_$i.wav",
),
);
}
} else {
if (withPop) context.loaderOverlay.hide();
showFlushbar(context, 'file and field count doesnt same.',
color: Colors.red);
return {
'status': false,
'message': 'file and field count doesnt same.',
};
}
}
final res = await client.send(Request(
method: method == APIMethod.post ? "POST" : "GET",
url: "http://$baseUrl/$path",
headers: {"Content-Type": "multipart/mixed"},
// body: RequestBody.raw(utf8.encode("hello world")),
// body: RequestBody.string("hello world"),
// body: RequestBody.form({"age": "10", "hello": "world"}),
body: RequestBody.multipart(multiparts),
));
List<int> resBody = res.body;
Map<String, dynamic> resMap = res.headers;
String resText = res.text();
print('body: $resBody');
print('map: $resMap');
print('text: $resText');
I/flutter (31072): libcurl/7.72.0-DEV BoringSSL zlib/1.2.11 brotli/1.0.1 nghttp2/1.42.0
I/flutter (31072): body: [33, 33, 69, 88, 67, 69, 80, 84, 73, 79, 78, 33, 33, 10, 77, 105, 109, 101, 77, 117, 108, 116, 105, 112, 97, 114, 116, 69, 120, 99, 101, 112, 116, 105, 111, 110, 58, 32, 66, 97, 100, 32, 109, 117, 108, 116, 105, 112, 97, 114, 116, 32, 101, 110, 100, 105, 110, 103]
I/flutter (31072): map: {date: Wed, 29 Mar 2023 14:52:09 GMT, content-length: 58, x-frame-options: SAMEORIGIN, content-type: text/plain; charset=utf-8, x-xss-protection: 1; mode=block, x-content-type-options: nosniff, server: dart:io with Shelf}
I/flutter (31072): text: !!EXCEPTION!!
I/flutter (31072): MimeMultipartException: Bad multipart ending
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.7.8, on Microsoft Windows [Version 10.0.19044.1526], locale ja-JP)
[√] Windows Version (Installed version of Windows is version 10 or higher)
Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.6)
[√] Android Studio (version 2020.3)
[!] Android Studio (version 4.1)
X Unable to determine bundled Java version.
[√] VS Code (version 1.76.2)
[√] Connected device (4 available)
[√] HTTP Host Availability
! Doctor found issues in 1 category.
It seems that bindings are pretty useful out of flutter context, and I cant find any usage of package:flutter
outside of tests and example.
Would it be possible to distribute underlying bindings as separate package without flutter
dependency to allow using it in dart server apps?
Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :flutter_curl project caused this error: E:\curl_demo_new\build\flutter_curl\libs\curl.aar.
I am getting this error while running the project. I have added plugin directly in pubspec.yaml.
Error (Xcode): In /Users/{user_name}/.pub-cache/hosted/pub.dev/flutter_curl-0.2.0/ios/Curl.framework/Curl(nghttp2_pq.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/{user_name}/.pub-cache/hosted/pub.dev/flutter_curl-0.2.0/ios/Curl.framework/Curl' for architecture arm64
Could not build the application for the simulator.
Error launching application on iPhone 14 Pro Max.
xcode version 14.2
ios version 16.0
flutter doctor -v output
[✓] Flutter (Channel stable, 3.7.9, on macOS 13.3 22E252 darwin-arm64, locale en-IN)
• Flutter version 3.7.9 on channel stable at /Users/{user_name}/Development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 62bd79521d (4 days ago), 2023-03-30 10:59:36 -0700
• Engine revision ec975089ac
• Dart version 2.19.6
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
• Android SDK at /Users/{user_name}/Library/Android/sdk
• Platform android-33, build-tools 33.0.2
• ANDROID_HOME = /Users/{user_name}/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.12.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
[✓] Connected device (3 available)
• iPhone 14 Pro Max (mobile) • A9ED1A36-88A0-485A-9A7A-E350E60A1E12 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-0 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.3 22E252 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 111.0.5563.146
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
curl can connect to proxy so this library should too.
Linux natively has curl. Why not support it?
Windows has a native wrapper for curl as well in powershell.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.