mirror of
				https://github.com/KevinMidboe/immich.git
				synced 2025-10-29 17:40:28 +00:00 
			
		
		
		
	Get thumbnail from app (#68)
* Renamed multipart filed name 'files' to 'assetData'. * Added an additional field name of 'thumbnailData' to multipart form. * Implemented upload mechanism for thumbnail directly from the mobile client. * Removed dead code * Implemented a version checking mechanism.
This commit is contained in:
		| @@ -30,10 +30,14 @@ class BackupService { | ||||
|       Function(int, int) uploadProgress) async { | ||||
|     var dio = Dio(); | ||||
|     dio.interceptors.add(AuthenticatedRequestInterceptor()); | ||||
|  | ||||
|     String deviceId = Hive.box(userInfoBox).get(deviceIdKey); | ||||
|     String savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey); | ||||
|     File? file; | ||||
|  | ||||
|     MultipartFile assetRawUploadData; | ||||
|     MultipartFile thumbnailUploadData; | ||||
|  | ||||
|     for (var entity in assetList) { | ||||
|       try { | ||||
|         if (entity.type == AssetType.video) { | ||||
| @@ -43,12 +47,20 @@ class BackupService { | ||||
|         } | ||||
|  | ||||
|         if (file != null) { | ||||
|           FormData formData; | ||||
|           String originalFileName = await entity.titleAsync; | ||||
|           String fileNameWithoutPath = originalFileName.toString().split(".")[0]; | ||||
|           var fileExtension = p.extension(file.path); | ||||
|           var mimeType = FileHelper.getMimeType(file.path); | ||||
|  | ||||
|           var formData = FormData.fromMap({ | ||||
|           assetRawUploadData = await MultipartFile.fromFile( | ||||
|             file.path, | ||||
|             filename: fileNameWithoutPath, | ||||
|             contentType: MediaType( | ||||
|               mimeType["type"], | ||||
|               mimeType["subType"], | ||||
|             ), | ||||
|           ); | ||||
|           formData = FormData.fromMap({ | ||||
|             'deviceAssetId': entity.id, | ||||
|             'deviceId': deviceId, | ||||
|             'assetType': _getAssetType(entity.type), | ||||
| @@ -57,18 +69,36 @@ class BackupService { | ||||
|             'isFavorite': entity.isFavorite, | ||||
|             'fileExtension': fileExtension, | ||||
|             'duration': entity.videoDuration, | ||||
|             'files': [ | ||||
|               await MultipartFile.fromFile( | ||||
|                 file.path, | ||||
|                 filename: fileNameWithoutPath, | ||||
|                 contentType: MediaType( | ||||
|                   mimeType["type"], | ||||
|                   mimeType["subType"], | ||||
|                 ), | ||||
|               ), | ||||
|             ] | ||||
|             'assetData': [assetRawUploadData] | ||||
|           }); | ||||
|  | ||||
|           // Build thumbnail multipart data | ||||
|           var thumbnailData = await entity.thumbDataWithSize(1280, 720); | ||||
|           if (thumbnailData != null) { | ||||
|             thumbnailUploadData = MultipartFile.fromBytes( | ||||
|               List.from(thumbnailData), | ||||
|               filename: fileNameWithoutPath, | ||||
|               contentType: MediaType( | ||||
|                 "image", | ||||
|                 "jpeg", | ||||
|               ), | ||||
|             ); | ||||
|  | ||||
|             // Send thumbnail data if it is exist | ||||
|             formData = FormData.fromMap({ | ||||
|               'deviceAssetId': entity.id, | ||||
|               'deviceId': deviceId, | ||||
|               'assetType': _getAssetType(entity.type), | ||||
|               'createdAt': entity.createDateTime.toIso8601String(), | ||||
|               'modifiedAt': entity.modifiedDateTime.toIso8601String(), | ||||
|               'isFavorite': entity.isFavorite, | ||||
|               'fileExtension': fileExtension, | ||||
|               'duration': entity.videoDuration, | ||||
|               'thumbnailData': [thumbnailUploadData], | ||||
|               'assetData': [assetRawUploadData] | ||||
|             }); | ||||
|           } | ||||
|  | ||||
|           Response res = await dio.post( | ||||
|             '$savedEndpoint/asset/upload', | ||||
|             data: formData, | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| import 'package:dio/dio.dart'; | ||||
| import 'package:immich_mobile/shared/models/mapbox_info.model.dart'; | ||||
| import 'package:immich_mobile/shared/models/server_version.model.dart'; | ||||
| import 'package:immich_mobile/shared/services/network.service.dart'; | ||||
| import 'package:immich_mobile/shared/models/server_info.model.dart'; | ||||
|  | ||||
| @@ -17,4 +18,10 @@ class ServerInfoService { | ||||
|  | ||||
|     return MapboxInfo.fromJson(response.toString()); | ||||
|   } | ||||
|  | ||||
|   Future<ServerVersion?> getServerVersion() async { | ||||
|     Response response = await _networkService.getRequest(url: 'server-info/version'); | ||||
|  | ||||
|     return ServerVersion.fromJson(response.toString()); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user