Skip to content

Instantly share code, notes, and snippets.

@drexel-ue
Created June 19, 2019 19:52
Show Gist options
  • Save drexel-ue/f04fc3d6e0a492a41777d08b315d30d3 to your computer and use it in GitHub Desktop.
Save drexel-ue/f04fc3d6e0a492a41777d08b315d30d3 to your computer and use it in GitHub Desktop.
void _uploadVideo(UserData userData) async {
String selectedFilter = _filterTitleSubject.value ?? 'Normal';
final url = 'http://10.0.2.2:8888/videos';
final body = {
'userID': userData.id,
'createdBy': userData.displayName,
'appliedFilter': selectedFilter,
'title': title,
'aspectRatio': json.encode(cameraController.value.aspectRatio),
'content': content,
'public': json.encode(public),
'latitude': json.encode(latitude),
'longitude': longitude.toString(),
'type': type,
'duration':
json.encode(videoPlayerController.value.duration.inMilliseconds),
'startTime': json.encode(startTime),
};
var request = http.MultipartRequest('POST', Uri.parse(url));
request.fields.addAll(body);
_upload.forEach((UploadFile uploadFile) {
var multiFile = http.MultipartFile.fromBytes(
'video',
uploadFile.file.readAsBytesSync(),
filename: _videoPath,
contentType: uploadFile.type,
);
request.files.add(multiFile);
});
print('>>>>>ATTEMPTING UPLOAD');
final response = await request.send();
if (response.statusCode == 200) {
_upload.clear();
print("UPLOADED!");
} else {
print('>>>RESPONSE ${response.reasonPhrase}');
}
_clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment