I want to send a POST request to a camera and receive a motionJPEG stream back. I am using the Dart http package. As far as I can tell, I cannot use http.post to receive a stream as the response. I am trying to use http.Client.send. I do not know how to create a proper body and header for the http.Request.
Most IP cameras use a GET to access the MotionJPEG byte stream. However, the camera I am using is a RICOH THETA camera and it requires a POST command with a payload to be sent to the camera. If anyone knows how I can create a proper POST Request to return a stream with header and body using the dart http module, please help.
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
main() async {
Uri url = Uri.parse('https://192.168.1.1/osc/commands/execute');
var request = http.Request('POST', url);
Map<String, String> bodyMap = {'name': 'camera.getLivePreview'};
request.body = jsonEncode(bodyMap);
Map<String, String> headers = {"Content-type": "application/json"};
http.Client client = http.Client();
StreamSubscription videoStream;
client.head(url, headers: headers);
client.send(request).then((response) {
var startIndex = -1;
var endIndex = -1;
List<int> buf = List<int>();
videoStream = response.stream.listen((List<int> data) {
for (var i = 0; i < data.length; i++) {
print(data[i]);
}
});
});
}