takeUploadFile method
사진업로드
이미지를 카메라 또는 갤러리로 부터 가져와서, 이미지 누어서 찍힌 이미지를 바로 보정을 하고, 압축을 하고, 서버에 업로드
deletePreviousUpload
가 true 이면, 기존에 업로드된 동일한 taxonomy 와 entity 파일을 삭제한다.
Implementation
Future<ApiFile> takeUploadFile({
required ImageSource source,
int quality = 90,
bool deletePreviousUpload = false,
String taxonomy = '',
int entity = 0,
String code = '',
required Function? onProgress,
}) async {
/// Pick image
final picker = ImagePicker();
final pickedFile = await picker.getImage(source: source);
if (pickedFile == null) throw ERROR_IMAGE_NOT_SELECTED;
if (kIsWeb) {
// final image = Image.network(pickedFile.path);
final bytes = await pickedFile.readAsBytes();
/// Upload with binary bytes
return await uploadFile(
bytes: bytes,
deletePreviousUpload: deletePreviousUpload,
onProgress: onProgress,
taxonomy: taxonomy,
entity: entity,
code: code,
);
} else {
// If it's mobile.
File? file;
// If there is image compressor (mostly only mobile.)
if (imageCompressor != null) {
file = await imageCompressor!(pickedFile.path, quality);
} else {
// if there is no compresstor.
file = File(pickedFile.path);
}
print('code: $code in api.controller.dart::takeUploadfile');
/// Upload with file
return await uploadFile(
file: file,
deletePreviousUpload: deletePreviousUpload,
onProgress: onProgress,
taxonomy: taxonomy,
entity: entity,
code: code,
);
}
}