uploadFile method
Future<FileModel?>
uploadFile(
- String fileName,
- String fileType,
- Uint8List fileBytes, {
- bool makeThumbnail = false,
- String usageType = "content",
- String? bucketId,
override
Implementation
@override
Future<FileModel?> uploadFile(
String fileName,
String fileType,
Uint8List fileBytes, {
bool makeThumbnail = false,
String usageType = "content",
String? bucketId,
}) async {
try {
bucketId ??= myConfig!.serverConfig.storageConnInfo.bucketId;
fileName = StorageUtils.sanitizeString(
StorageUtils.getMD5(fileBytes) + Uri.encodeComponent(fileName));
late String folderPath;
if (usageType == "content") {
if (fileType.contains("image")) {
folderPath = "/content/image/";
} else if (fileType.contains("video")) {
folderPath = "/content/video/";
makeThumbnail = true;
} else {
folderPath = "/content/etc/";
if (fileType.contains("pdf")) makeThumbnail = true;
}
} else if (usageType == "bookThumbnail") {
folderPath = "/book/thumbnail/";
} else if (usageType == "profile") {
folderPath = "p/rofile/";
} else if (usageType == "banner") {
folderPath = "/banner/";
} else {
folderPath = "/etc/";
}
String? fileId = '$bucketId$folderPath$fileName';
//print('fileId:$fileId');
final fileExit = await getFileData(fileId);
//파일이 이미 존재 하면
if (fileExit != null) {
//print('파일이 이미 존재 해요 fileId:$fileExit');
return fileExit;
} else {
//print('파일이 존재 하지 않아요. 업로드를 진행 합니다.');
}
// 썸네일 작동후 확인
if (makeThumbnail) {
// ignore: unused_local_variable
final createThumbnailResult =
await createThumbnail(folderPath, fileName, fileType, bucketId);
//print('썸네일 생성 결과:$createThumbnailResult');
// 썸네일 생성 안되고 있음 왜 인지?(펑션스 문제?)
}
// ignore: unused_local_variable
final result = await Supabase.instance.client.storage
.from(mainBucketId)
.uploadBinary(fileId, fileBytes);
//print('uploadFile success!! result:$result');
//result에 오는 값 : hycop/ks-park-sqisoft-com.3ca5a91e9da54c6e8e10781758e3e4d5/content/image/05ede4a4a175bd4f538ca018ab3e1a72test1.jpg
return await getFileData(fileId);
} catch (e) {
logger.severe('uploadFile error:$e');
return null;
}
}