io static method
Implementation
static Future io(
List<int> filePath, {
required OnUploadProgress onUploadProgress,
required String privateKey,
required String fileName,
String? folder,
}) async {
String apiUrl = "https://upload.imagekit.io/api/v1/files/upload";
String username = privateKey;
String password = '';
String basicAuth =
'Basic ${base64Encode(utf8.encode('$username:$password'))}';
// String fileName = file.name.split('/').last;
var formData = FormData.fromMap({
'file': MultipartFile.fromBytes(filePath, filename: fileName),
'fileName': fileName,
'folder': folder ?? "flutter_imagekit",
});
try {
Response response = await Dio().post(
apiUrl,
data: formData,
options: Options(headers: {'authorization': basicAuth}),
onSendProgress: (count, total) {
double progress = count / total;
onUploadProgress(progress);
},
);
final getApi = response.data;
if (kDebugMode) {
print(getApi["url"]);
}
return getApi;
} on DioError catch (e) {
if (kDebugMode) {
print(e.message);
}
}
}