uploadDocument method
Implementation
Future<int> uploadDocument(
String srcPath,
String fileName,
bool isPublic,
Uint8List? bytes,
) async {
final int hashId =
DateTime.now().millisecondsSinceEpoch + Random().nextInt(1000);
String fileType = _getFileExt(fileName);
final targetDocuments = isPublic ? publicDocument : privateDocument;
final tmpUploadDoc = DocumentInfo(
isUploading: true,
docName: fileName,
docType: fileType,
hashId: hashId,
transcodeState: 1,
cosUploadProgress: 0,
);
final finalVal = targetDocuments.copyWith(
documents: [tmpUploadDoc, ...targetDocuments.documents],
);
if (isPublic) {
publicDocument = finalVal;
} else {
privateDocument = finalVal;
classDocument = classDocument.copyWith(
documents: [tmpUploadDoc, ...classDocument.documents],
); // 更新班级文档列表中的文档
}
update();
// 将任务加入队列
_uploadQueue.add(
UploadTask(
srcPath: srcPath,
fileName: fileName,
isPublic: isPublic,
fileType: fileType,
hashId: hashId,
tmpUploadDoc: tmpUploadDoc,
bytes: bytes,
),
);
// 如果没有正在进行的上传,则开始处理队列
if (_currentUpload == null) {
_processNextUpload();
}
return hashId;
}