瀏覽代碼

Bug fix in livephoto upload flow

Neeraj Gupta 4 年之前
父節點
當前提交
854a021cc8
共有 2 個文件被更改,包括 18 次插入15 次删除
  1. 15 11
      lib/utils/file_uploader_util.dart
  2. 3 4
      lib/utils/file_util.dart

+ 15 - 11
lib/utils/file_uploader_util.dart

@@ -5,8 +5,9 @@ import 'dart:typed_data';
 import 'package:archive/archive_io.dart';
 import 'package:logging/logging.dart';
 import 'package:motionphoto/motionphoto.dart';
-import 'package:path_provider/path_provider.dart';
+import 'package:path/path.dart';
 import 'package:photo_manager/photo_manager.dart';
+import 'package:photos/core/configuration.dart';
 import 'package:photos/core/constants.dart';
 import 'package:photos/core/errors.dart';
 import 'package:photos/models/file.dart' as ente;
@@ -66,20 +67,25 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(ente.File file) async {
     throw InvalidFileError();
   }
 
+  // h4ck to fetch location data if missing (thank you Android Q+) lazily only during uploads
+  await _decorateEnteFileData(file, asset);
+
   if (file.fileType == FileType.livePhoto && io.Platform.isIOS) {
     final io.File videoUrl = await Motionphoto.getLivePhotoFile(file.localID);
-    final tempPath = (await getTemporaryDirectory()).path;
-    final zipFilePath = tempPath + "/" + file.title + ".zip";
+    final tempPath =  Configuration.instance.getTempDirectory();
+    final zipFilePath = tempPath + file.generatedID.toString() + ".zip";
+    _logger.fine("Uploading zipped live photo from " + zipFilePath);
     var encoder = ZipFileEncoder();
     encoder.create(zipFilePath);
-    encoder.addFile(videoUrl);
-    encoder.addFile(sourceFile);
+    encoder.addFile(videoUrl, "video" + extension(videoUrl.path));
+    encoder.addFile(sourceFile, "image" + extension(sourceFile.path));
     encoder.close();
-    // delete the temporary video and image copy
-    sourceFile.deleteSync();
-    videoUrl.deleteSync();
+    // delete the temporary video and image copy (only in IOS)
+    if(io.Platform.isIOS) {
+      sourceFile.deleteSync();
+    }
+    // new sourceFile which needs to be uploaded
     sourceFile = io.File(zipFilePath);
-    _logger.fine("Uploading zipped live photo from " + sourceFile.path);
   }
 
   thumbnailData = await asset.thumbDataWithSize(
@@ -98,8 +104,6 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(ente.File file) async {
   }
 
   isDeleted = asset == null || !(await asset.exists);
-  // h4ck to fetch location data if missing (thank you Android Q+) lazily only during uploads
-  await _decorateEnteFileData(file, asset);
   return MediaUploadData(sourceFile, thumbnailData, isDeleted);
 }
 

+ 3 - 4
lib/utils/file_util.dart

@@ -7,8 +7,8 @@ import 'package:flutter_cache_manager/flutter_cache_manager.dart';
 import 'package:flutter_image_compress/flutter_image_compress.dart';
 import 'package:logging/logging.dart';
 import 'package:motionphoto/motionphoto.dart';
-import 'package:path/path.dart';
 import 'package:photos/core/cache/image_cache.dart';
+import 'package:path/path.dart';
 import 'package:photos/core/cache/video_cache_manager.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/constants.dart';
@@ -41,7 +41,7 @@ Future<io.File> getFile(ente.File file) async {
 }
 
 Future<io.File> getLiveVideo(ente.File file) async {
-  Motionphoto.getLivePhotoFile(file.localID);
+  return Motionphoto.getLivePhotoFile(file.localID);
 }
 
 Future<io.File> _getLocalDiskFile(ente.File file) async {
@@ -98,8 +98,7 @@ Future<io.File> getFileFromServer(ente.File file,
   });
 }
 
-Future<io.File> _downloadAndCache(
-    ente.File file, BaseCacheManager cacheManager,
+Future<io.File> _downloadAndCache(ente.File file, BaseCacheManager cacheManager,
     {ProgressCallback progressCallback}) async {
   return downloadAndDecrypt(file, progressCallback: progressCallback)
       .then((decryptedFile) async {