upload<T> static method
Implementation
static Future<T> upload<T>(
RepositoryBase repository,
MediumHelper helper,
String? base,
String? ext,
int mediumType,
dynamic theItem,
String? relatedMediumId,
{Map<String, String>? newDocumentIds}) async {
base ??= noNameId;
if (newDocumentIds != null) {
var baseId = base.substring(0, 36);
if (baseId == noNameId) {
base = newRandomKey();
} else {
var newBaseID = newDocumentIds[baseId];
if (newBaseID != null) {
base = newBaseID + base.substring(16);
}
}
}
var baseName = "$base.${ext ?? ''}";
var thumbNailName = "$base-thumb.${ext ?? ''}";
var extractItem = theItem['extract'];
if (mediumType == 0) {
var extract = Uint8List.fromList(extractItem.cast<int>());
// Photo
return await helper.createThumbnailUploadPhotoData(
theItem['documentID'], extract, baseName, thumbNailName,
relatedMediumId: relatedMediumId);
} else if (mediumType == 1) {
var extract = Uint8List.fromList(extractItem.cast<int>());
// Video
return await helper.createThumbnailUploadVideoData(
theItem['documentID'],
extract,
baseName,
thumbNailName,
);
} else if (mediumType == 2) {
var extract = Uint8List.fromList(extractItem.cast<int>());
// Pdf
return await helper.createThumbnailUploadPhotoData(
theItem['documentID'], extract, baseName, thumbNailName,
relatedMediumId: relatedMediumId);
} else if (mediumType == 3) {
// Txt
return await helper.uploadTextData(
theItem['documentID'],
extractItem,
baseName,
);
}
throw Exception(
"Exception during upload of base $base, ext $ext: mediumType $mediumType not supported");
}