getFileData method
Implementation
@override
Future<FileModel?> getFileData(String fileId, {String? bucketId}) async {
try {
// 폴더 경로와 파일 이름을 한 줄로 분리
String fullPath = fileId;
String folderPath = fullPath.substring(0, fullPath.lastIndexOf('/'));
String fileName = fullPath.split('/').last;
final fileObjects = await Supabase.instance.client.storage
.from(mainBucketId)
.list(path: folderPath);
if (fileObjects.isNotEmpty) {
FileObject? fileObject = fileObjects.firstWhereOrNull(
(file) => file.name == fileName,
);
//print('fileObject:${fileObject?.toDetailString()}');
//TO DO 썸네일 작동후 확인
String thumbnailId =
"${fullPath.substring(0, fullPath.indexOf("/"))}/content/thumbnail/${fileName.substring(0, fileName.lastIndexOf("."))}.jpg";
//print('thumbnailId:$thumbnailId');
String? thumbnailUrl = await getPublicFileUrl(thumbnailId);
//print('getFileData fileId:$fileId, success!!');
return FileModel(
id: fullPath,
name: fileName.substring(32),
url: '${await getPublicFileUrl(fullPath)}',
thumbnailUrl: '$thumbnailUrl',
size: fileObject?.metadata!['size'],
contentType: ContentsType.getContentTypes(
fileObject?.metadata!['mimetype']));
} else {
return null;
}
} catch (e) {
//print('getFileObject error:$e');
logger.severe('uploadFile error:$e');
return null;
}
}