Skip to content

Commit 883e250

Browse files
committed
exif metadata
1 parent cf7afbe commit 883e250

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

lib/services/upload/Uploader.dart

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import 'dart:convert';
2+
import 'dart:io';
23

34
import 'package:dio/dio.dart';
45
import 'package:flutter/material.dart';
56
import 'package:flutter/services.dart';
7+
import 'package:flutter_image_compress/flutter_image_compress.dart';
68
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
79
import 'package:image_picker/image_picker.dart';
10+
import 'package:path_provider/path_provider.dart';
811
import 'package:piwigo_ng/api/API.dart';
912
import 'package:piwigo_ng/api/ImageAPI.dart';
1013
import 'package:piwigo_ng/constants/SettingsConstants.dart';
@@ -39,7 +42,7 @@ class Uploader {
3942
);
4043
}
4144

42-
Future<void> uploadPhotos(BuildContext context, List<XFile> photos, String category, Map<String, dynamic> info) async {
45+
Future<void> uploadPhotos(BuildContext context, List<XFile> photos, String category, Map<String, dynamic> info,) async {
4346
Map<String, dynamic> result = {
4447
'isSuccess': true,
4548
'filePath': null,
@@ -63,9 +66,12 @@ class Uploader {
6366
for(var element in photos) {
6467
uploadStatusProvider.status = true;
6568

66-
Response response = await uploadChunk(context, element, category, info,
69+
70+
XFile photo = await testCompressAndGetFile(element);
71+
72+
Response response = await uploadChunk(context, photo, category, info,
6773
(progress) {
68-
print(progress);
74+
debugPrint("$progress");
6975
uploadStatusProvider.progress = progress;
7076
},
7177
);
@@ -81,7 +87,7 @@ class Uploader {
8187
}
8288
uploadStatusProvider.reset();
8389
} on DioError catch (e) {
84-
print(e.message);
90+
debugPrint(e.message);
8591
uploadStatusProvider.reset();
8692
ScaffoldMessenger.of(context).hideCurrentSnackBar();
8793
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar(context, appStrings(context).uploadError_title));
@@ -90,13 +96,32 @@ class Uploader {
9096
try {
9197
await uploadCompleted(uploadedImages, int.parse(category));
9298
await communityUploadCompleted(uploadedImages, int.parse(category));
99+
100+
// cleanTempDirectory();
93101
} on DioError catch (e) {
94-
print(e.message);
102+
debugPrint(e.message);
95103
}
96104

97105
await _showUploadNotification(result);
98106
}
99107

108+
Future<XFile> testCompressAndGetFile(XFile file) async {
109+
110+
Directory cacheDir = await getTemporaryDirectory();
111+
112+
var result = await FlutterImageCompress.compressAndGetFile(
113+
await FlutterAbsolutePath.getAbsolutePath(file.path),
114+
cacheDir.absolute.path + file.name,
115+
);
116+
117+
return XFile(result.path, name: file.name);
118+
}
119+
120+
void cleanTempDirectory() async {
121+
Directory cacheDir = await getTemporaryDirectory();
122+
cacheDir.deleteSync(recursive: true);
123+
}
124+
100125
Future<Response> uploadChunk(BuildContext context, XFile photo,
101126
String category, Map<String, dynamic> info,
102127
Function(double) onProgress,
@@ -135,7 +160,7 @@ class Uploader {
135160
onUploadProgress: (value) => onProgress(value),
136161
);
137162
} on DioError catch (e) {
138-
print('Dio upload chunk error $e');
163+
debugPrint('Dio upload chunk error $e');
139164
ScaffoldMessenger.of(context).hideCurrentSnackBar();
140165
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar(context, appStrings(context).uploadError_title));
141166
return Future.value(null);

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies:
3131
permission_handler: ^8.3.0
3232
external_path: ^1.0.1
3333
flutter_local_notifications: ^9.1.2
34+
flutter_image_compress: ^1.1.0
3435

3536
# File pickers :
3637
image_picker: ^0.8.4+4

0 commit comments

Comments
 (0)