upload method
Handle Uploads
Implementation
Future<PlanningCenterApiResponse> upload(String filename) async {
// if we are using app secret authentication, it will be embedded in the _uploadsUri
// if not, we try to populate the _authHeaders
var authFailure = await _checkCredentials();
if (authFailure != null) return authFailure;
var request = http.MultipartRequest('POST', _uploadsUri);
var fileBytes = File(filename).readAsBytesSync();
var fileToPost = http.MultipartFile.fromBytes('file', fileBytes);
request.files.add(fileToPost);
request.headers.addAll(_authHeaders);
var res = await http.Response.fromStream(await request.send());
if (res.statusCode >= 200 && res.statusCode < 300) {
var retval = PlanningCenterApiResponse.fromResponse(
'-upload-',
PlanningCenterApiQuery(),
'',
res,
);
return retval;
}
return PlanningCenterApiError(
'UPLOAD Failed',
'-upload-',
_uploadsUri,
'',
PlanningCenterApiQuery(),
res.statusCode,
res.body,
);
}