makes cli upload of an image work
Some checks failed
piwigodotnet/pipeline/head This commit looks good
SideCarJpgCleaner/pipeline/head There was a failure building this commit

This commit is contained in:
Philipp Häfelfinger 2022-11-19 10:10:56 +01:00
parent 3b2384d82f
commit b30fd4ad2a

View File

@ -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)