Created
October 19, 2012 10:05
-
-
Save maiah/3917285 to your computer and use it in GitHub Desktop.
File Upload Sample in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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