Skip to content

Instantly share code, notes, and snippets.

@maiah
Created October 19, 2012 10:05
Show Gist options
  • Save maiah/3917285 to your computer and use it in GitHub Desktop.
Save maiah/3917285 to your computer and use it in GitHub Desktop.
File Upload Sample in Dart
final List<int> data = new List<int>();
req.inputStream.onData = () {
data.addAll(req.inputStream.read());
};
req.inputStream.onClosed = () {
String dataString = new String.fromCharCodes(data);
List<String> contents = dataString.split('\n');
String webKitFormBoundary = contents[0];
String contentDisposition = contents[1];
String contentType = contents[2];
String fileBody = '';
for (int i = 4; i < (contents.length - 2); i++) {
String content = contents[i];
if (!content.startsWith(webKitFormBoundary)) {
fileBody = '$fileBody$content\n';
}
}
res.write(fileBody);
res.outputStream.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment