diff --git a/src/Piwigo.Client.Cli/UploadHandler.cs b/src/Piwigo.Client.Cli/UploadHandler.cs index 8cc6686..d0d56ea 100644 --- a/src/Piwigo.Client.Cli/UploadHandler.cs +++ b/src/Piwigo.Client.Cli/UploadHandler.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using Piwigo.Client.Images; namespace Piwigo.Client.Cli; @@ -10,10 +11,21 @@ internal static class UploadHandler try { + var imageToUpload = new FileInfo(options.ImagePath); + var md5Sum = await imageToUpload.CalculateMd5SumAsync(); + logger.LogInformation(EventIds.Upload, "Uploading {ImagePath}", options.ImagePath); var client = PiwigoClient.CreateClient(options.ServerUrl, options.UserName, options.Password, loggerFactory); - var result = await client.UploadImageAsync(new FileInfo(options.ImagePath)); + await client.Session.LoginAsync(); + + var imageUpload = new ImageUpload(md5Sum) + { + Albums = options.AlbumId.HasValue ? new List<(int AlbumId, int? Rank)> { new(options.AlbumId.Value, null) } : null + }; + + var result = await client.UploadImageAsync(imageToUpload, imageUpload); logger.LogInformation(EventIds.ActionSucceeded, "Uploaded {ImagePath} with new image id {ImageId}", options.ImagePath, result.ImageId); + return EventIds.ActionSucceeded.Id; } catch (PiwigoException ex)