Convert HEIC images to JPG before uploading
This commit is contained in:
parent
f294e16b11
commit
e0d6c831bc
4 changed files with 25 additions and 7 deletions
|
@ -2,6 +2,7 @@ import 'dart:io';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
|
@ -64,7 +65,17 @@ class Photo {
|
|||
});
|
||||
});
|
||||
} else {
|
||||
return getAsset().originBytes;
|
||||
final originalBytes = getAsset().originBytes;
|
||||
if (extension(title) == ".HEIC" || quality != 100) {
|
||||
return originalBytes.then((bytes) {
|
||||
return FlutterImageCompress.compressWithList(bytes, quality: quality)
|
||||
.then((converted) {
|
||||
return Uint8List.fromList(converted);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return originalBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,10 +89,6 @@ class Photo {
|
|||
return Configuration.instance.getHttpEndpoint() + "/" + thumbnailPath;
|
||||
}
|
||||
|
||||
Future<Uint8List> getOriginalBytes() {
|
||||
return getAsset().originBytes;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Photo(generatedId: $generatedId, uploadedFileId: $uploadedFileId, localId: $localId, title: $title, deviceFolder: $deviceFolder, remotePath: $remotePath, createTimestamp: $createTimestamp, updateTimestamp: $updateTimestamp)';
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:path_provider/path_provider.dart';
|
|||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
|
||||
import 'package:photos/core/configuration.dart';
|
||||
|
@ -197,11 +198,13 @@ class PhotoSyncManager {
|
|||
|
||||
Future<Photo> _uploadFile(Photo localPhoto) async {
|
||||
var formData = FormData.fromMap({
|
||||
"file": MultipartFile.fromBytes((await localPhoto.getOriginalBytes()),
|
||||
"file": MultipartFile.fromBytes((await localPhoto.getBytes()),
|
||||
filename: localPhoto.title),
|
||||
"deviceFileID": localPhoto.localId,
|
||||
"deviceFolder": localPhoto.deviceFolder,
|
||||
"title": localPhoto.title,
|
||||
"title": extension(localPhoto.title) == ".HEIC"
|
||||
? basenameWithoutExtension(localPhoto.title) + ".JPG"
|
||||
: localPhoto.title,
|
||||
"createTimestamp": localPhoto.createTimestamp,
|
||||
});
|
||||
return _dio
|
||||
|
|
|
@ -132,6 +132,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
flutter_image_compress:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_image_compress
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.8"
|
||||
flutter_launcher_icons:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
|
|
@ -46,6 +46,7 @@ dependencies:
|
|||
flutter_email_sender: ^3.0.1
|
||||
like_button: ^0.2.0
|
||||
logging: ^0.11.4
|
||||
flutter_image_compress: ^0.6.5+1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue