dart-io

How to catch SIGINT for the current in Dart?

帅比萌擦擦* 提交于 2019-12-01 05:29:49
问题 How can Ctrl + C or SIGINT be caught in a Dart program for the current process? Something similar to this for Node: process.on('SIGINT', function() { // do stuff }); 回答1: I found the following test code at Unified Diff: tests/standalone/io/signals_test_script.dart import "dart:io"; void main(args) { int usr1Count = int.parse(args[0]); int usr2Count = int.parse(args[1]); var sub1; var sub2; void check() { if (usr1Count < 0 || usr2Count < 0) exit(1); if (usr1Count == 0 && usr2Count == 0) { sub1

How to use Dart http_server:VirtualDirectory

时光总嘲笑我的痴心妄想 提交于 2019-11-30 21:14:44
I have been using the dart:route api for serving static files but I noticed that there is a core library called http_server that contains helper classes and functions for dart:io HttpServer . Of particular interest to me is the class VirtualDirectory which, according to the docs, takes a String Object for the static content of directory and then you call the method serve() var virtualDirectory = new VirtualDirectory('/var/www/'); virtualDirectory.serve(new HttpServer('0.0.0.0', 8080)); This doesn't work as there is no constructor for HttpServer - at least not in current versions.

How to use Dart http_server:VirtualDirectory

◇◆丶佛笑我妖孽 提交于 2019-11-30 04:44:29
问题 I have been using the dart:route api for serving static files but I noticed that there is a core library called http_server that contains helper classes and functions for dart:io HttpServer . Of particular interest to me is the class VirtualDirectory which, according to the docs, takes a String Object for the static content of directory and then you call the method serve() var virtualDirectory = new VirtualDirectory('/var/www/'); virtualDirectory.serve(new HttpServer('0.0.0.0', 8080)); This

Dart how to upload image

安稳与你 提交于 2019-11-29 15:36:46
I'm trying to upload an image, here's the code : server.dart import 'dart:io'; void main() { HttpServer.bind('127.0.0.1', 8080) .then((HttpServer server) { server.listen((HttpRequest request) { if (request.method.toLowerCase() == 'post') { request.fold(new BytesBuilder(), (builder, data) => builder..add(data)) .then((BytesBuilder builder) { File file = new File('abc.jpg'); file.writeAsBytes(builder.takeBytes(), mode: FileMode.WRITE) .then((_) { request.response.close(); }); }); } else { File f = new File('test_1.html') ..openRead().pipe(request.response); } }); }); } test_1.html <!DOCTYPE html

Http POST request with json content-type in dart:io

佐手、 提交于 2019-11-29 11:56:46
问题 How to perform HTTP POST using the console dart application (using dart:io or may be package:http library. I do something like that: import 'package:http/http.dart' as http; import 'dart:io'; http.post( url, headers: {HttpHeaders.CONTENT_TYPE: "application/json"}, body: {"foo": "bar"}) .then((response) { print("Response status: ${response.statusCode}"); print("Response body: ${response.body}"); }).catchError((err) { print(err); }); but get the following error: Bad state: Cannot set the body

DART post with multipart/form-data

こ雲淡風輕ζ 提交于 2019-11-29 11:42:53
in DART lang, how to specify POST request Content-Type to be multipart/form-data My DART code is: sendDatas(dynamic data) { final req = new HttpRequest(); req.onReadyStateChange.listen((Event e) { if (req.readyState == HttpRequest.DONE && (req.status == 200 || req.status == 0)) { window.alert("upload complete"); } }); req.open("POST", "/upload"); req.send(data); } I am doing POST with a file Robert I think you should use HttpRequest.postFormData(url, data) here. Then you can use the following: FormData data = new FormData(); // from dart:html data.append(key, value); HttpRequest.request('

Access to user environment variable

╄→尐↘猪︶ㄣ 提交于 2019-11-29 09:30:15
In my .bashrc file: export DART_SDK=/home/nicolas/dart/dart-sdk In command line, it works when I "echo" it. But I cannot see this user variable from dart with, I just see system variable but not mine: var env = Platform.environment; env.forEach((k,v) => print("Key=$k Value=$v")); I tried: on windows and it works on mac but doesn't work Is my user variable is not well defined? Is my code is bad? It's a bug? Cutch Using the following code: import 'dart:io'; // Server side / command line only package. main() { Map<String, String> env = Platform.environment; env.forEach((k, v) => print("Key=$k

Dart how to upload image

依然范特西╮ 提交于 2019-11-28 09:07:37
问题 I'm trying to upload an image, here's the code : server.dart import 'dart:io'; void main() { HttpServer.bind('127.0.0.1', 8080) .then((HttpServer server) { server.listen((HttpRequest request) { if (request.method.toLowerCase() == 'post') { request.fold(new BytesBuilder(), (builder, data) => builder..add(data)) .then((BytesBuilder builder) { File file = new File('abc.jpg'); file.writeAsBytes(builder.takeBytes(), mode: FileMode.WRITE) .then((_) { request.response.close(); }); }); } else { File

DART post with multipart/form-data

寵の児 提交于 2019-11-28 05:32:01
问题 in DART lang, how to specify POST request Content-Type to be multipart/form-data My DART code is: sendDatas(dynamic data) { final req = new HttpRequest(); req.onReadyStateChange.listen((Event e) { if (req.readyState == HttpRequest.DONE && (req.status == 200 || req.status == 0)) { window.alert("upload complete"); } }); req.open("POST", "/upload"); req.send(data); } I am doing POST with a file 回答1: I think you should use HttpRequest.postFormData(url, data) here. Then you can use the following:

Access to user environment variable

佐手、 提交于 2019-11-28 03:01:48
问题 In my .bashrc file: export DART_SDK=/home/nicolas/dart/dart-sdk In command line, it works when I "echo" it. But I cannot see this user variable from dart with, I just see system variable but not mine: var env = Platform.environment; env.forEach((k,v) => print("Key=$k Value=$v")); I tried: on windows and it works on mac but doesn't work Is my user variable is not well defined? Is my code is bad? It's a bug? 回答1: Using the following code: import 'dart:io'; // Server side / command line only