Skip to content

Instantly share code, notes, and snippets.

@drexel-ue
Created June 20, 2019 14:17
Show Gist options
  • Save drexel-ue/e1f35c71c2d9b1664f570d285247023b to your computer and use it in GitHub Desktop.
Save drexel-ue/e1f35c71c2d9b1664f570d285247023b to your computer and use it in GitHub Desktop.
@Operation.post()
Future<Response> handleUpload() async {
final transformer = MimeMultipartTransformer(
request.raw.headers.contentType.parameters["boundary"]);
final parts = await transformer
.bind(Stream.fromIterable([await request.body.decode<List<int>>()]))
.toList();
parts.forEach((MimeMultipart part) {
part.listen((List<int> data) async {
await File(
'uploads/${request.raw.headers.value('userID')}_${request.raw.headers.value('startTime')}.mp4')
.writeAsBytes(data);
});
});
final query = Query<Video>(context)
..values.userID = request.raw.headers.value('userID')
..values.createdBy =
Uri.decodeComponent(request.raw.headers.value('createdBy'))
..values.appliedFilter = request.raw.headers.value('appliedFilter')
..values.title = request.raw.headers.value('title')
..values.aspectRatio =
json.decode(request.raw.headers.value('aspectRatio')) as double
..values.content = request.raw.headers.value('content')
..values.public = json.decode(request.raw.headers.value('public')) as bool
..values.latitude =
json.decode(request.raw.headers.value('latitude')) as double
..values.longitude =
json.decode(request.raw.headers.value('longitude')) as double
..values.type = request.raw.headers.value('type')
..values.duration =
json.decode(request.raw.headers.value('duration')) as int
..values.startTime =
json.decode(request.raw.headers.value('startTime')) as int;
final response = await query.insert();
return Response.ok(
{
'response': response,
'info':
'${Uri.decodeComponent(request.raw.headers.value('createdBy'))}${request.raw.headers.value('latitude')}_${request.raw.headers.value('longitude')}_${request.raw.headers.value('title')}',
},
);
}
<asynchronous suspension>
#17 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#18 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#19 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#20 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
#21 _MapStream._handleData (dart:async/stream_pipe.dart:232:10)
#22 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
#23 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#24 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#25 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#26 _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
#27 _StreamController._add (dart:async/stream_controller.dart:640:7)
#28 _StreamController.add (dart:async/stream_controller.dart:586:5)
#29 _HttpServer._handleRequest (dart:_http/http_impl.dart:2656:19)
#30 new _HttpConnection.<anonymous closure> (dart:_http/http_impl.dart:2414:19)
#31 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#32 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#33 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#34 _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
#35 _StreamController._add (dart:async/stream_controller.dart:640:7)
#36 _StreamController.add (dart:async/stream_controller.dart:586:5)
#37 _HttpParser._headersEnd (dart:_http/http_parser.dart:386:17)
#38 _HttpParser._doParse (dart:_http/http_parser.dart:701:15)
#39 _HttpParser._parse (dart:_http/http_parser.dart:318:7)
#40 _HttpParser._onData (dart:_http/http_parser.dart:810:5)
#41 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#42 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#43 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#44 _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
#45 _StreamController._add (dart:async/stream_controller.dart:640:7)
#46 _StreamController.add (dart:async/stream_controller.dart:586:5)
#47 _Socket._onData (dart:io-patch/socket_patch.dart:1774:41)
#48 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#49 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#50 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#51 _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
#52 _StreamController._add (dart:async/stream_controller.dart:640:7)
#53 _StreamController.add (dart:async/stream_controller.dart:586:5)
#54 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1323:33)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment