create method
dynamic
create()
Create a new upload throwing ProtocolException on server error
Implementation
create() async {
_fileSize = await file.length();
final client = getHttpClient();
final createHeaders = Map<String, String>.from(headers ?? {})
..addAll({
"Tus-Resumable": tusVersion,
"Upload-Metadata": _uploadMetadata ?? "",
"Upload-Length": "$_fileSize",
});
final response = await client.post(url, headers: createHeaders);
if (!(response.statusCode >= 200 && response.statusCode < 300) &&
response.statusCode != 404) {
throw ProtocolException(
"unexpected status code (${response.statusCode}) while creating upload");
}
String urlStr = response.headers["location"] ?? "";
if (urlStr.isEmpty) {
throw ProtocolException(
"missing upload Uri in response for creating upload");
}
_uploadUrl = _parseUrl(urlStr);
store?.set(_fingerprint, _uploadUrl as Uri);
}